IOS-生成二维码

生成二维码

 CIFilter *qrcodefilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
 [qrcodefilter setDefaults];  
 NSString *str = @"http://www.jianshu.com/u/51716bf1008a";
 NSData *data2 = [str dataUsingEncoding:NSUTF8StringEncoding];
 [qrcodefilter setValue:data2 forKey:@"inputMessage"];
 CIImage *outputImage = [qrcodefilter outputImage];

二维码大小

CGFloat qrcodescaleX = 120 / outputImage.extent.size.width; // extent 返回图片的frame
CGFloat qrcodescaleY = 120 / outputImage.extent.size.height;

压缩图片

CIImage *tranImage = [outputImage imageByApplyingTransform:CGAffineTransformScale(CGAffineTransformIdentity, qrcodescaleX, qrcodescaleY)];
UIImage *rcode_image=[UIImage imageWithCIImage:tranImage];

重新赋值

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(HCSystemWidth *0.5 -50, 120, 100, 100)]; imageView.image = rcode_image;
imageView.backgroundColor = [UIColor clearColor];
[self addSubview:imageView];

你可能感兴趣的:(IOS-生成二维码)