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.
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.
Related
I have followed a number of tutorials in adding a custom font to my SwiftUI package. I have take the following steps:
Add Font Awesome 5 Free Solid-900.otf to my project.
Made sure that the font is copied and added to the target
Added the font file names to the Fonts provided by application array in Info.plist
Tried to get the font name
Tried a large number of permutations and combinations for the font name.
I tried the following:
Text(Text("\u{f071} Danger Will Robinson").font(.custom("Font Awesome 5 Free Regular", size: 20))
which is supposed to give me an alert icon, but all I get is a question mark.
Is there a trick to using Font Awesome in this way?
I know there are a few packages available, but I’m trying to learn more about the process itself, and I can’t see that it should be too hard.
OK, I worked it out.
For MacOS, the Info.plist key is: Application fonts resource path, not as above.
The next trick is to get the font name.
One method is to install the font, and then check FontBook. The PostScript name is the name I need.
The other is to run the following code:
let fontManager = NSFontManager.shared
let fonts = fontManager.availableFonts
for name in fonts {
print(name)
}
That’s what happens when all the tutorials are for iOS, not MacOS.
Is it possible to load a font from disk and use it during run-time?
If so, how/where do you store the fonts on the iphone/ipod/ipad for your app to use?
(To be clear, I'm not talking about adding the font as a resource at design-time. I'm asking about a way to allow a user to select a font file during run-time, loading it, and making it available for use.)
You should put them (.ttf, .otf) into your info-plist under UIAppFonts then you can "use" them with setFont: withSize:
You add your font as a resource, add it to your info.plist under Fonts provided by application (UIAppFonts) array, then use it as any embedded one.
Ok, in that case take a look at FontLabel project.
One thing though, looking through it's code - you can only get CGFontRef and with kind of voodoo work with it, no conversion between CGFontRef and UIFont really exists. See this question
In my application i need to display arabic text with different custom fonts. I follow the scenario adding ttf files to info.plist.
As per above scenario i am successfully getting display text in different font style for ENGLISH text only. I am doing same thing for arabic font styles but here i am not getting. Why is going like that?
Please any one can help me
Thanks in Advance.
#Kareem , I took hint from Stackoverflow itself to load the fonts but could not get it working in first go. May be following steps can help you .
Add the font files to your project.
Make their entries in info.plist file
such as
you can now implement some method that loads your font somewhere in
application delegate
like
-(UIFont*) CustomFontWithSize:(float)size{
UIFont* customFont = [UIFont fontWithName:#"FX_Masa" size:size];
if(customFont == nil)
customFont = [UIFont systemFontOfSize:size];
return customFont;
}
If you notice then the name I have passes here is "FX_MASA" and not FX_MasaRegular , this was the point where I was wrong. The name that we need to use while fetching the font is the INSTALL NAME (Double click on the font to install the font on system and the name that appears in Font Book is the install name).
Hope this helps your problem as well. In case you come across any good method, please update here.
There is a nice UILabel extension in GitHub called "Font Label": https://github.com/zynga/FontLabel
This allows to load any TTF file and then draw ZLabel objects (ZLabel is an extension of UILabel) with this custom font. It is based on CoreGraphics and I tested with many custom fonts and proved to work correctly. I don't know of course the effect with arabic fonts, but it's worth a try and a feedback from you (to us and also the github project admins) is welcome.
I've downloaded a font that's called "aldo the apache (.tff) " from dafont.com.
I used it with different programms like adobe illustrator and it seemed to work just fine.
Recently i tried to use it in a game that i'm making to experement. It didn't work -_-.
IB was displaying the font as a slightly bigger version of arial.
How can i solve this problem and get the font to display correctly?
If you have any suggestions, please post them down below.
-DD
You have to edit your <appname>-Info.plist file and create a new UIAppFonts key with type array, where each element is a String with the name of your font file, in this case AldotheApache.ttf. Then use the name in IB or with UIFont as it shows in the application Font Book app of your Mac, in your case Aldo the Apache. Obviously the font should also be added as a resource of your project.
How do I use custom TTF fonts in my Cocos2d iPhone apps?
I searched for this for a while and decided to post as question and answer for people wanting to implement.
The solution is quite easy.
Find the fonts you want and download them. This website has a huge collection of free fonts.
Add the font files to your project.
Add the font names to your info.plist file using the array below as an example.
Find the font's name; Double click the font file and use the font name shown in the title of the window. In this example it is "Action Man"
To use the font name the way you would normally:
CCLabel* myLabel = [CCLabel labelWithString:#"Some Text" fontName:#"Action Man" fontSize:18];
Add this to your info.plist file:
<key>UIAppFonts</key>
<array>
<string>Action Man Bold.ttf</string>
<string>AdineKirnberg-S.ttf</string>
</array>
In Cocos2D, you can include the font file with your resources and then in fontName: simply supply the filename. For example:
CCLabelTTF *label = [CCLabelTTF labelWithString:#"whatever" fontName:#"FONTNAME.ttf" fontSize:18];
This is often easier than the method Hanaan has posted.
You should use the exact same file name capitalisation as the filename.
You do not need to add fonts to your info.plist if you are only using it in Cocos2D bits.
If, like Confused, you find that the font works on the simulator but not the device, it is probably a file name capitalisation mistake. The iPhone is case-sensitive, the simulator is not.
As these answers are outdated, I'm sure my question/ answer will help all those out there.
Importing fonts for cocos2dx iOS
this is for iOS and Android platform font importing, with just a single line of code!