Barcode Generation from within iOS App

喜欢而已 提交于 2019-11-26 12:07:19

问题


I want to take a numerical string and generate a simple barcode that can be read by any scanner.

I can already use the camera and read a barcode but now I would like to generate a barcode.

Does anyone know of an sdk that will allow me to do this, resources or code snipets?

Thank you


回答1:


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




回答2:


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 :-)




回答3:


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:




回答4:


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




回答5:


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 ]



来源:https://stackoverflow.com/questions/5759073/barcode-generation-from-within-ios-app

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