之前找了一个生成二维码第三方libqrencode,但是在xcode6的64为环境下有很多关于数据类型方面的警告,后来找了一个类ZXingObjC:https://github.com/TheLevelUp/ZXingObjC生成二维码。
从github下载的demo里的example文件夹下的QrCodeTest文件夹里放的是生成二维码的demo。生成二维码需要以一下文件:
在xcode6里引入以上文件后可能会报错,原因是没有引入Foundation框架,可以建立一个预编译文件,在预编译文件里引入Foundation框架。然后仿照demo里的方法生成二维码:
- (IBAction)generateQRCode:(id)sender {
[self.textField resignFirstResponder];
NSString *data = self.textField.text;
if (data == 0) return;
ZXMultiFormatWriter *writer = [[ZXMultiFormatWriter alloc] init];
ZXBitMatrix *result = [writer encode:data
format:kBarcodeFormatQRCode
width:self.imageView.frame.size.width
height:self.imageView.frame.size.width
error:nil];
if (result) {
ZXImage *image = [ZXImage imageWithMatrix:result];
self.imageView.image = [UIImage imageWithCGImage:image.cgimage];
} else {
self.imageView.image = nil;
}
}

3151

被折叠的 条评论
为什么被折叠?



