30

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

Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
Raymond
  • 477
  • 2
  • 5
  • 15

5 Answers5

31

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

Jano
  • 62,815
  • 21
  • 164
  • 192
  • ok, I got the Cocoa-Touch-Barcodes, does anyone have any sample code of how to make this work. I am just wanting a standard barcode to be generated when I pass it an alpha numeric string. I will then display this to the user. – Raymond Apr 27 '11 at 21:22
  • 1
    ZXing works great, but suffers lots of bloat if all you are interested in is encoding one barcode type (like type 39). – LJ Wilson May 15 '13 at 18:59
  • i found that this project has been abandoned in a state that makes it unfit for use in actual iOS apps. Which Is why I started my own libray to generate bar codes. Code 39 was very simple to implement, since it doesn't have any fancy checkdigit-code-page-alternating ... – Cocoanetics Aug 20 '13 at 20:03
15

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

7

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:

Barcode

Durai Amuthan.H
  • 31,670
  • 10
  • 160
  • 241
6

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

Andrew Romanov
  • 4,774
  • 3
  • 25
  • 40
0

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 ]

NANNAV
  • 4,875
  • 4
  • 32
  • 50
Patrick Lin
  • 166
  • 1
  • 4