libqrencode使用
1、將libqrencode文件夾整個拖入項目文件夾中
2、在要生成二維碼的頁面的 .m文件頭部添加 #import "QRCodeGenerator.h"
二維碼的view部分代碼
UIView *downView = [[UIView alloc]initWithFrame:CGRectMake(15, 100, SCREEN_WIDTH-30, SCREEN_HEIGHT-200)];
downView.tag = 10;
downView.alpha = 0.9;
downView.backgroundColor = TEXT_COLOR;
UIImageView *downIOSView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, downView.frame.size.width, downView.frame.size.height-60)];
downIOSView.backgroundColor = [UIColor whiteColor];
UIImage *image = [QRCodeGenerator qrImageForString:detModel.down_ios imageSize:downIOSView.bounds.size.width];
[downIOSView setImage:image];
UIButton *dismissBtn = [[UIButton alloc]initWithFrame:downIOSView.frame];
dismissBtn.backgroundColor = [UIColor clearColor];
[dismissBtn addTarget:self action:@selector(dismissview:) forControlEvents:UIControlEventTouchUpInside];
[downView addSubview:dismissBtn];
[downView addSubview:downIOSView];
[self.view addSubview:downView];
點擊二維碼彈出二維碼的view消失
-(void)dismissview:(UIButton *)sender
{
for(UIView *subViews in [self.view subviews])
{
if(subViews.tag ==10)
{
[subViews removeFromSuperview];
}
}
}
3、編譯時QRCodeGenerator.h文件報錯
解決方法:在QRCodeGenerator.h頭部添加 #import <UIKit/UIKit.h>