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>