我想将数字字符串转换成简单的条形码,以便任何扫描器都能够读取。
我已经能够使用相机读取条形码,但现在我想生成一个条形码。
有没有人知道可以让我实现这个功能的SDK、资源或代码片段?
谢谢
#import "NKDBarcodeFramework.h"
,并在您的初始化函数中添加以下代码。barcode = [NKDExtendedCode39Barcode alloc];
barcode = [barcode initWithContent:@"1234567890123" printsCaption:0];
[barcode calculateWidth];
NSLog(@"%@",[barcode description]);
theImage = [UIImage imageFromBarcode:barcode];
subview = [[UIImageView alloc]initWithFrame:TTScreenBounds()];
[subview setImage:theImage];
[self addSubview:subview];
self.frame = self.bounds;
玩得开心 :-)
有很多种条形码类型
每种条形码类型都有很多子类型,每个子类型都有其自身的用途。
我将解释如何生成一种 One D 条形码类型的 Code 39 码。
这里我将解释如何使用自定义字体生成该条形码。
步骤:
1)从此处下载自定义字体。
2)从下载的压缩包中附加 FRE3OF9X.ttf 文件。
3)在 info.plist 中添加键应用提供的字体,并在item 0 中将值设置为 FRE3OF9X.ttf。
4)尝试下面的代码片段:
UIFont *fntCode39=[UIFont fontWithName:@"Free3of9Extended" size:30.0];
UILabel *lblBarCodeTest=[[UILabel alloc]initWithFrame:CGRectMake(0,100,768,30)];
[lblBarCodeTest setBackgroundColor:[UIColor lightGrayColor]];
[lblBarCodeTest setTextAlignment:NSTextAlignmentCenter];
[lblBarCodeTest setFont:fntCode39];
[lblBarCodeTest setText:@"*BarCode3Of9_AKA_Code39-ItsA1DBarcode*"];
[self.view addSubview:lblBarCodeTest];
我创建了一个简单的类来生成Code 39条形码,只需添加一个.h和一个.m文件到你的项目中,使用一行代码,它就可以为你生成包含Code 39编码数据的UIImage,像这样:
UIImage *code39Image = [Code39 code39ImageFromString:@"HELLO CODE39" Width:barcode_width Height:barcode_height];
这是项目在Github上的链接: [https://github.com/bclin087/Simple-Code39-generator-for-iOS.git ]