今天的功能为:生成条形码
非常简单,把代码复制到程序里,然后引用方法就好啦~ 人生如此美妙。
1.生成条形码-(参数1.条形码内容 参数2.条形码宽度 参数3.条形码高度 返回的是UIImage)
+ (UIImage *)generateBarCode:(NSString *)code width:(CGFloat)width height:(CGFloat)height {
//生成条形码
CIImage *barcodeImage;
NSData *data = [codedataUsingEncoding:NSISOLatin1StringEncodingallowLossyConversion:false];
CIFilter *filter = [CIFilterfilterWithName:@"CICode128BarcodeGenerator"];
[filter setValue:dataforKey:@"inputMessage"];
barcodeImage = [filter outputImage];
//消除模糊
CGFloat scaleX = width / barcodeImage.extent.size.width;// extent 返回图片的frame
CGFloat scaleY = height / barcodeImage.extent.size.height;
CIImage *transformedImage = [barcodeImageimageByApplyingTransform:CGAffineTransformScale(CGAffineTransformIdentity, scaleX, scaleY)];
return [UIImageimageWithCIImage:transformedImage];
}
感谢观看,学以致用更感谢!