Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

NSString+FontAwesome

NotificationsYou must be signed in to change notification settings

alexdrone/ios-fontawesome

Repository files navigation

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

This category brings this great iconic font on iOS.

Usage

First, make sure you haveFontAwesome.ttf bundled in your project and thatUIAppFonts key in the project's plist file contains a String item namedFontAwesome.ttfThen add theNSString+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 herehttp://fortawesome.github.io/Font-Awesome/icons

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

or you can add theUIImage+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 calleddefaultView 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 (withInstaFont 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 fileFontAwesome.ttf with a tool likettx for example and use the new name inNSString+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 theFontAwesome.ttf file tottx format

    cd your_app/Pods/FontAwesome+iOS/Resources/ttx FontAwesome.ttf
  • Replace all occurence ofFontAwesome withFontAwesome440 for example inttx file and save

  • Convert backttx font tottf

    ttx FontAwesome.ttxmv FontAwesome.ttf FontAwesome.ttf.origmv FontAwesome#1.ttf FontAwesome.ttf
  • In fileNSString+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 athttps://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)

About

NSString+FontAwesome

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp