Barcode Generation from within iOS App

假装没事ソ 提交于 2019-11-27 06:38:00

The only free library to do this is Cocoa-Touch-Barcodes, which is a fork of cocoabarcodes. If you are considering commercial libraries, there is one called iPhone Barcode Generator.

update Check this objective-c port of ZXing: https://github.com/TheLevelUp/ZXingObjC

Include : #import "NKDBarcodeFramework.h" in your Header File and put these lines below in your init function.

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;

have fun :-)

There are so many barcode types

  • One D
  • Two D
  • Three D

Each barcode type has so many subtypes and each has its own purpose.

I explain how to generate one of the One D barcode type code 39

here i explain how to generate that barcode using Custom font

Steps:

1)Download the custom font from here

2)Attach the file FRE3OF9X.ttf from the downloaded zip

3)add the key Fonts provided by application in info.plist and in item 0 give FRE3OF9X.ttf as value

4)Try the below code snippet

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];

Result:

You can use CoreImage to generate Barcode images. CoreImage contains 4 filters to generate different barcodes: CICode128BarcodeGenerator, CIQRCodeGenerator, CIPDF417BarcodeGenerator, CIAztecCodeGenerator.

Patrick Lin

I've created a simple class for generating Code 39 Barcode, only one .h and one .m needed to add to your project, and with one line of code it generates the UIImage with code 39 encoded data for you, like this:

UIImage *code39Image = [Code39 code39ImageFromString:@"HELLO CODE39" Width:barcode_width Height:barcode_height];

Here's the link to the project on github: [https://github.com/bclin087/Simple-Code39-generator-for-iOS.git ]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!