So I am trying to use this font http://fortawesome.github.com/Font-Awesome/. I've added the font as a resource and put it in the plist file. Here's how I am using it:
[homeFeedButton.titleLabel setFont:[UIFont fontWithName:@"fontawesome" size:8]];
NSString *str = [NSString stringWithFormat:@"%C", @"\f030"];
However this doesn't work. Does anyone know how to use this font in an Xcode project?
It is because your
+[NSString stringWithFormat:]
method contains the literal for a unichar, not an NSString, which is an object that uses %@, which is beside the point because literal'ing a literal is redundant.This may help someone else... I had about 90% of Font Awesome icons working in my project, except a handful of them I couldn't get them to display correctly. They'd instead display a "..." icon instead.
After several hours of investigating unicode characters in Objective-C, I realised I was barking up the wrong tree! "..." isn't a FontAwesome icon, it's UIKit telling me that the frame of the UILabel is too small/font too large to display the text string! D'oh.
You can just use the literal code string by affixing it with
\u
.e.g. You can use
\f030
in your iOS app using the following snippet.[[[UILabel alloc] initWithFrame:CGRectZero] setText:@"\uf030"];
NSLog your all font using following code and provide exact name.
In case anyone is wondering, import the following in the .m file.
Here is an example for a cell's label text:
Make sure you get the font name correct as suggested above.