NSString+FontAwesome

Related tags

Font ios-fontawesome
Overview

FontAwesome+iOS

Font awesome is an iconic font. Read more about it on http://fortawesome.github.com/Font-Awesome/

This category brings this great iconic font on iOS.

Usage

First, make sure you have FontAwesome.ttf bundled in your project and that UIAppFonts key in the project's plist file contains a String item named FontAwesome.ttf Then add the NSString+FontAwesome category to the project.

UILabel *label = [...]
label.font = [UIFont fontWithName:kFontAwesomeFamilyName size:20];

You can now use enums for all the different iconic characters

label.text = [NSString fontAwesomeIconStringForEnum:FAGithub];

or you can reference them by using the class identifiers listed here http://fortawesome.github.io/Font-Awesome/icons

label.text = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-github"];

or you can add the UIImage+FontAwesome category to generate icon image directly

UIImage *github = [UIImage imageWithIcon:@"fa-github" backgroundColor:[UIColor purpleColor] iconColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:255] iconScale:2.f fontSize:20];

then you will get an icon like this

image

That's all.
Have a look at the small demo project for further information.

FAImageView

FAImageView is now extended and contains a new property called defaultView that is shown when the image is set to nil. It is possible to use one the font-awesome icon as a default placeholder for an image view.

FAImageView *imageView = [[FAImageView alloc] initWithFrame:CGRectMake(0.f, 0.f, 100.f, 100.f)];
imageView.image = nil;
[imageView setDefaultIconIdentifier:@"fa-github"];

Troubleshooting

Some icons are not available on some devices

Keep in mind that if you have installed the FontAwesome font in your iOS system (with InstaFont for example), the embedded font in your App will not be used! So if your system FontAwesome font is v4.2, you will never be able to display icons from v4.3 and v4.4 for example from the embedded font.

Two solutions :

  1. Remove the font profile from your iOS device
  2. Rename the Postscript name of file FontAwesome.ttf with a tool like ttx for example and use the new name in NSString+FontAwesome.h

Here is the step by step for second solution :

  • Install fonttools

    git clone https://github.com/behdad/fonttools.git ;
    cd fonttools/
    sudo python setup.py install
    
  • Convert the FontAwesome.ttf file to ttx format

    cd your_app/Pods/FontAwesome+iOS/Resources/
    ttx FontAwesome.ttf
    
  • Replace all occurence of FontAwesome with FontAwesome440 for example in ttx file and save

  • Convert back ttx font to ttf

    ttx FontAwesome.ttx
    mv FontAwesome.ttf FontAwesome.ttf.orig
    mv FontAwesome#1.ttf FontAwesome.ttf
    
  • In file NSString+FontAwesome.h, change font Postscript name :

    static NSString *const kFontAwesomeFamilyName = @"FontAwesome440";
    
  • Build, run and dance

License

This project uses the FontAwesome fix made by Pit Garbe that you can find at https://github.com/leberwurstsaft/FontAwesome-for-iOS Version 2.0 of the Font Awesome font, CSS, and LESS files are licensed under CC BY 3.0: http://creativecommons.org/licenses/by/3.0/ A mention of 'Font Awesome - http://fortawesome.github.com/Font-Awesome' in human-readable source code is considered acceptable attribution (most common on the web). If human readable source code is not available to the end user, a mention in an 'About' or 'Credits' screen is considered acceptable (most common in desktop or mobile software)

Comments
  • Some characters are not aligned center.

    Some characters are not aligned center.

    Please check the screenshot. I add fonts in tableview cells and the UILabels' frame are the same. Is it a font issue? Screen Shot 2013-01-25 at 2 30 40 AM

    BTW, I'm interested how can you reference the character for font-awesome with integer value? I know little about fonts things. Would you please give me some hint or keyword to research?

    opened by ewangke 5
  • Added Podspec

    Added Podspec

    Hi Alex,

    A great project you have here. We wanted to use it in our application using Cocoapods so I created a podspec.

    Here it is if you'd like to include it so others can use your project in Cocoapods. Cocoapods will recommend that you tag a release and update the Podspec accordingly. I can help with this if you'd like to tag a 1.0.0.

    Thanks for creating this!

    • Viet Pham
    opened by vphamdev 3
  • Cocoapods

    Cocoapods

    Hi,

    Thanks for this really useful lib, I was about to make mine when I found yours. I'd love to use it with Cocoapods, even if I can do it "myself" in my podfile, it'll be great for the community if you could release this on CocoaPods.

    If you need help writing the pod spec (https://github.com/CocoaPods/CocoaPods/wiki/The-podspec-format) and submitting it to Cocoapods, I'll be glad to help.

    Thanks!!!

    opened by jmig 3
  • Add: Podspec file + Install instructions

    Add: Podspec file + Install instructions

    I've explained how to install and use in the README.

    @alexdrone if you want, you can tag this version, specify the tag in the podspec and submit your library to the master repo of pods : https://github.com/CocoaPods/Specs

    opened by jmig 2
  • Only works with enum but not with string id

    Only works with enum but not with string id

    if I use FAIconxxx it works, but if I try string id "fa-xxx" or simply "xxx" it always shows the default image.

    I included all the header files already. Anything missing?

    opened by ipeisong 1
  • Added a whole bunch of missing icons. Also created nicer demo with complete list.

    Added a whole bunch of missing icons. Also created nicer demo with complete list.

    This also updated the font to the ttf with the baseline fixes (3.0) and removes FontAwesome as a submodule. Hope you can integrate since it has all icons (but one)

    opened by runmad 1
  • Added a whole bunch of missing icons. Also created nicer demo with complete list.

    Added a whole bunch of missing icons. Also created nicer demo with complete list.

    Icons can now be viewed in a list with their icon and name in alphabetical order. I have also added a bunch of missing icons. The list is now at 248, so there's one icon missing, not sure which one :)

    opened by runmad 1
  • Added missing icons. Fixed icon-user-md

    Added missing icons. Fixed icon-user-md

    icon-user-md had an incorrect unicode character.

    I also added a number of icons that were missing, however there are still a number of icons missing (currently 218 icons out of 249 total are available in ios-fontawesome). I'll try and add more when I get time, I just added ones that I needed for a project so far, plus a few extra.

    opened by runmad 1
  • CocoaPods

    CocoaPods

    I am running a fork here: https://github.com/paramaggarwal/FontAwesome-iOS that is using the name FontAwesome on CocoaPods.

    The code is exactly this repo itself. I would like that repo to be merged into this one and I would like to hand over ownership of the CocoaPod to you. Please get in touch with me using the email on my Github Profile.

    Excellent work with the repo, @alexdrone!

    opened by paramaggarwal 0
  • Add String+FontAwesome.swift as alternate to NSString+FontAwesome.m

    Add String+FontAwesome.swift as alternate to NSString+FontAwesome.m

    I've found that in pure swift environments (in my case, a WatchKit app extension, where the FontAwesome library was in another dynamic framework), loading the iconStrings fail, due to the hex string conversion (In ObjC you can do "\uf02" but in Swift you must do "\u{f102}")

    If there is a better solution that doesn't require having to add a swift file with the newer-syntax hex strings, I'm all for it. I just made this to fit into my project, and thought it might be useful for others.

    Note that I haven't added the swift file to the .podspec as we don't want to force anyone's project to start including the swift runtime.

    opened by rsattar 0
  • Failed to download 'FontAwesome+iOS'

    Failed to download 'FontAwesome+iOS'

    ==> pod update Update all pods

    Analyzing dependencies Pre-downloading: FontAwesome+iOS from [email protected]:alexdrone/ios-fontawesome.git

    [!] Error installing FontAwesome+iOS [!] Failed to download 'FontAwesome+iOS'.

    Same error with pod install

    ==> pod install Analyzing dependencies Pre-downloading: FontAwesome+iOS from [email protected]:alexdrone/ios-fontawesome.git

    [!] Error installing FontAwesome+iOS [!] Failed to download 'FontAwesome+iOS'.

    opened by arunabhdas 1
  • Icon not showing and app crash on second access

    Icon not showing and app crash on second access

    Hi,

    I have just included the NSString+FontAwesome.h and .m on my project along with FontAwesome.ttf. I made the changes on info.plist and also verified that Build Phase is correct copying the resources. I also checked the output folder and expected files are there.

    So now the problem is the icon is not shown when I first access. just a box with an ? appear then when try to access a second time app chrash on the following method:

    • (NSString*)fontAwesomeIconStringForEnum:(FAIcon)value { return [NSString fontAwesomeUnicodeStrings][value]; }

    with error: EXC_BAD_ACCESS

    Thanks in advance,

    -Martin

    opened by mhermosi 2
  • Add some missing alias icons, e.g. fa-edit/fa-close

    Add some missing alias icons, e.g. fa-edit/fa-close

    Some icons are missing in master branch (most of them are alias icons), e.g. fa-edit/fa-close, this PR is about to add those icons back. Demo is also updated to include the new added icons.

    opened by enix223 0
Owner
Alex Usbergo
Technical Lead | Sr Software Engineer at Google. Ex-Microsoft/Ex-Skype.
Alex Usbergo
A better choice for iOS Developer to use FontAwesome Icon with UI.😍

FontAwesomeKit.Swift ?? ?? A better choice for iOS Developer to use FontAwesome Icon with UI. ?? Support Swift 4.2 & iOS 8.0+ FontAwesome 4.7.0 Storyb

Qiun Cheng 192 May 16, 2022
Use 1600+ icons (and more!) from FontAwesome and Google Material Icons in your swift/iOS project in an easy and space-efficient way!

Swicon Use 1600+ icons from FontAwesome and Google Material Icons in your iOS project in an easy and space-efficient way! The built-in icons are from

Zhibo 39 Nov 3, 2022
A category on NSString to convert Emoji Cheat Sheet codes to their equivalent Unicode characters

NSString+Emojize A category on NSString to turn codes from Emoji Cheat Sheet into Unicode emoji characters. Getting Started In order to use NSString+E

DIY.org 643 Sep 8, 2022
Use FontAwesome in your Swift projects

FontAwesome.swift Use Font Awesome in your Swift projects To see the complete set of 3,978 icons in Font Awesome 5, please check the FontAwesome.com s

Thi Doãn 1.6k Dec 30, 2022
A better choice for iOS Developer to use FontAwesome Icon with UI.😍

FontAwesomeKit.Swift ?? ?? A better choice for iOS Developer to use FontAwesome Icon with UI. ?? Support Swift 4.2 & iOS 8.0+ FontAwesome 4.7.0 Storyb

Qiun Cheng 192 May 16, 2022
Use 1600+ icons (and more!) from FontAwesome and Google Material Icons in your swift/iOS project in an easy and space-efficient way!

Swicon Use 1600+ icons from FontAwesome and Google Material Icons in your iOS project in an easy and space-efficient way! The built-in icons are from

Zhibo 39 Nov 3, 2022