views:

46

answers:

1

Hi All,

Just wondering what is the best way to display a barcode given a string on the iPhone. I have looked over stackoverflow and google and a few people have different ways each requiring a decent amount of work (I think) and also slightly old so I wanted to get it right first time.

One way I've read is using a custom font that you can now use in iOS4, using this font Someone else has written a class to import custom fonts, though this apparently isn't needed for iPads.

I have also found a Library but not much further details on it.

If using the font is the best way is the font linked above good or are there better ones?

Cheers for any help.

+1  A: 

Well I went ahead and checked it out anyway. Fonts work extremely well and are very easy to implement. Basically copy this barcode font into your project. Then in your App info.plist type this in:

<key>UIAppFonts</key>
<array>
<string>3OF9_NEW.TTF</string>
</array>

For the above linked font.

Then in where you want to place the barcode just use a UILabel and then for the font use :

label.font = [UIFont fontWithName:@"3 of 9 Barcode" size:40];

Note that the font name is not 30F9_NEW.TTF. If you are using another barcode font or other font in general just open the ttf file in font book and it will say the name up the top of the window. Also you need to have a * at the beginning and end of the string you are using. If you navigated here looking at how to implement a custom font you can do it the same way, just not the font name isn't the file name.

Rudiger
Many barcode systems aren't too complicated. Maybe as a challenge for yourself you could generate them using code rather than using a font.
dreamlax
Heh, I'm sorta over challenges for the moment and just want to finish it. The library at the top might already have a solution though.
Rudiger