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:
I have made a library in swift language with easy integration for UILabel
, UIButton
and UIBarButtonItem
. Also supports Pods. Font Awesome Swift
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 also use the library FontAwesome+iOS for iOS
Then you only need to use this code:
label.text = [NSString fontAwesomeIconStringForIconIdentifier:@"icon-github"];
// or:
label.text = [NSString fontAwesomeIconStringForEnum:FAIconGithub];
Below is the code to set image to a UIButton using FontAwesome
UIButton *btnMenu = [UIButton buttonWithType:UIButtonTypeCustom];
btnMenu.frame = CGRectMake(0, 0, 40, 32);
[btnMenu setTitle:@"\uf0c9" forState:UIControlStateNormal];
[btnMenu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btnMenu.titleLabel setFont:[UIFont fontWithName:@"FontAwesome" size:16]];
So, I can answer it for Swift & Objective C both. (using Swift 3.0 here)
Just download font-awesome from here: fontawesome.io and add .ttf to your project
Check the image below for more details...
let iconUniChar: UniChar = 0xf113
textLabel.text = String(format: "%C", iconUniChar)
_textLabel.text = [NSString stringWithFormat:@"%C", 0xf113];
And, if you are still facing the trouble here's the
NSLog your all font using following code and provide exact name.
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont)
{
NSLog(@" Font name: %@", [fontNames objectAtIndex:indFont]);
}
}