Icon font library for iOS. Currently supports Font-Awesome, Foundation icons, Zocial, and ionicons.
Currently FontAwesomeKit supports 4 different icon fonts.
- FontAwesome 4.4 Our old friend, contains 585 icons
- Foundation icons Contains 283 icons.
- Zocial Contains 99 social icons.
- ionicons 2.0.0 Contains 733 icons, lots of iOS 7 style outlined icons.
- Octicons 2.4.1 Contains 206 icons, built with love by Github.
- Material 2.0.0 Contains 743 icons, built by Google for Material design.
Thanks to NSAttributedString
the API is more clean and object oriented. All hail NSAttributedString
!
Please notice that FontAwesome has renamed lots of it's icons in the recent 4.0 release, make sure to change you code accordingly if you're using FontAwesomeKit 2.1 version.
- Xcode 5
- iOS 6.0 +
- ARC enabled
- CoreText framework
FontAwesomeKit now supports sub spec, only get the fonts you need.
Add pod 'FontAwesomeKit', '~> 2.1.0'
to Podfile to install all icon fonts.
Or select icon fonts with:
pod 'FontAwesomeKit/FontAwesome'
pod 'FontAwesomeKit/FoundationIcons'
pod 'FontAwesomeKit/Zocial'
pod 'FontAwesomeKit/IonIcons'
pod 'FontAwesomeKit/Octicons'
pod 'FontAwesomeKit/Material'
Run pod install
or pod update
to install selected icon fonts.
#import FontAwesomeKit/FontAwesomeKit.h
If you installed all available icon fonts.
Or import icon fonts you installed with sub specs
#import FontAwesomeKit/FAKFontAwesome.h
#import FontAwesomeKit/FAKFoundationIcons.h
#import FontAwesomeKit/FAKZocial.h
#import FontAwesomeKit/FAKIonIcons.h
#import FontAwesomeKit/FAKOcticons.h
#import FontAwesomeKit/FAKMaterialIcons.h
#####important: If you deleted a sub spec in Podfile, please delete Xcode's derived data in organizer(command+shift+2 to bring up). Otherwise Xcode will keep copying font files those supposed to be deleted to the app bundle.
Download source code, then drag the folder FontAwesomeKit
into your project, add CoreText framework to you project.
##Example Usage
FAKFontAwesome *starIcon = [FAKFontAwesome starIconWithSize:15];
FAKFoundationIcons *bookmarkIcon = [FAKFoundationIcons bookmarkIconWithSize:15];
FAKZocial *twitterIcon = [FAKZocial twitterIconWithSize:15];
FAKIonIcons *mailIcon = [FAKIonIcons ios7EmailIconWithSize:48];
FAKOcticons *repoIcon = [FAKOcticons repoIconWithSize:48];
FAKMaterialIcons *androidIcon = [FAKMaterialIcons androidIconWithSize:48];
Now you can use these class methods and pass in the font size instead of finding an icon with constants. Corresponding icon fonts will automatically setup for you.
It is now possible to use identifiers to create icons. Check each documentation to get the appropriate identifier. Also, make sure you use an existing identifier, else the method will return nil and an error will be set.
NSError *error;
FAKFontAwesome *starIcon = [FAKFontAwesome iconWithIdentifier:@"fa-star" size:15 error:error];
FAKFoundationIcons *bookmarkIcon = [FAKFoundationIcons iconWithIdentifier:@"fi-bookmark" size:15 error:error];
FAKZocial *twitterIcon = [FAKZocial iconWithIdentifier:@"zocial.twitter" size:15 error:error];
FAKIonIcons *mailIcon = [FAKIonIcons iconWithIdentifier:@"ion-ios-email" size:48 error:error];
[starIcon addAttribute:NSForegroundColorAttributeName value:[UIColor
whiteColor]];
NSAttributedString
did all the magics behind the scene. So you can set those attributes supported by NSAttributedString
to an icon. For all available attributes, see NSAttributedString UIKit Additions Reference
#####important:
Some attributes apparently makes no sense for icon fonts, like NSLigatureAttributeName
and NSKernAttributeName
. You should not use these attributes, otherwise you app might crash. And you should not set the value of NSFontAttributeName
, if you want to change the size of an icon, set it's iconFontSize
property instead.
These methods in fact are just shorthand versions for the standard NSAttributedString
API, should be pretty straightforward.
[starIcon setAttributes:attributes];
Sets attributes with a dictionary, will override current attribute if there're different values for a same key.
[starIcon removeAttribute:NSForegroundColorAttributeName];
Removes an attribute by name.
[starIcon attributes];
Returns an dictionary contains the attribute values for the icon.
[starIcon attribute:NSForegroundColorAttributeName];
Returns the attribute value for a given key.
After you done setting attributes, you can get the attributed string by calling
[starIcon attributedString]
.
So you can use the icon on a label with one line of code:
self.label.attributedText = [starIcon attributedString];
You don't need to set the label's font
property, it's already been taken care of.
Instead of getting the attributed string, you can draw the icon onto an image like this:
UIImage *iconImage = [starIcon imageWithSize:CGSizeMake(15, 15)];
This will use the attributes you've set to draw that image, you only need to specify a size for the image.
By default the icon is centered horizontally and vertically. I believe that's 99% what you want. However, if it's not centered properly, you can set the drawingPositionAdjustment
property for the icon, like this:
starIcon.drawingPositionAdjustment = UIOffsetMake(2, 2);
You can set the background color for the image like this:
starIcon.drawingBackgroundColor = [UIColor blackColor];
By default the background is transparent. As the name implies, this property only takes effect while drawing on image. You can specify a gradient color to create a gradient background, check the example project for details.
Some UI elements doesn't have an attributed string property, using images might be a better idea. Take UIBarButtonItem as an example.
FAKFontAwesome *cogIcon = [FAKFontAwesome cogIconWithSize:20];
[cogIcon addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor]];
UIImage *leftImage = [cogIcon imageWithSize:CGSizeMake(20, 20)];
cogIcon.iconFontSize = 15;
UIImage *leftLandscapeImage = [cogIcon imageWithSize:CGSizeMake(15, 15)];
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithImage:leftImage
landscapeImagePhone:leftLandscapeImage
style:UIBarButtonItemStylePlain
target:nil
action:nil];
Same idea can be applied to tab bar or segmented control.
Stacked icons is a feature of Font-Awesome and now has been ported to FontAwesomeKit. You can generate an image with multiple icons stacked together.
[UIImage imageWithStackedIcons:@[[FAKFontAwesome twitterIconWithSize:35], [FAKFontAwesome squareOIconWithSize:70]],
imageSize:CGSizeMake(80, 80)];
The first icon in the array will be draw on the bottom.
Please clone the master repo and take a look at the example project, everything is in it, all public methods and properties are documented. Feel free to open an issue if you went into trouble.
You can use some web applications like fontastic.me to generate your own icon font to reduce font file size. In this case, you need to implement your own FAKIcon
subclass, here's a complete demo: PrideChung / FontAwesomeKitCustomFont
Check Known Issuses if you ran into strange crashes.
See CHANGES.md
FontAwesomeKit is available under the MIT license. See the LICENSE file for more information. Attribution isn't required but is much appreciated.
Please notice that each icon font has it's own license agreement.