Auto-generated icon font library for iOS, watchOS and tvOS

Overview

Iconic Header

Travis codecov Pod Version Pod Platforms Swift Version License

Iconic helps making icon fonts integration effortless on iOS, tvOS and watchOS. Its main component is in charge of auto-generating strongly typed Swift code with SwiftGen, compatible with Objective-C.

You will interact with an auto-generated class under the name of {FontName}Icon.swift, which is a light abstraction of the IconDrawable.swift protocol. For more information, have a look at how to install and how to use.

Give Iconic a test drive by simply doing pod try Iconic in your terminal, and pick the Samples.xcworkspace.

Scale Example

Why Icon Fonts?

  • Resolution independent: scale and tint without quality loss
  • Automatically scaled for different screen densities
  • Work with (way) less image files
  • Improve visual consistency
  • Platform agnostic
  • Add better UI accessibility
  • Simple to work with

Where can I find awesome icon fonts?

Key Features

Note: Some open sourced icon fonts don't include the names of each of their glyphs. This could result in a non-descriptive enums, which can make things less intuitive for you when using Iconic. If you create your own icon font, make sure to properly name each glyph.

Installation

Via CocoaPods

Start by defining Iconic on your Podfile. Because we use an environment variable on a non-traditional setup, you will need to do it the following way:

pod 'Iconic', :git => 'https://github.com/home-assistant/Iconic.git', :tag => '1.3'

To install Iconic with a custom icon font, you need to use the FONT_PATH environment variable:

FONT_PATH='/Users/WillFerrell/Desktop/super-duper-font.otf' pod install

FONT_PATH='/Users/WillFerrell/Desktop/super-duper-font.otf' pod update Iconic

If you simply call pod install, Iconic will be installed using its default font, FontAwesome.

After the installation is complete, you should see 3 files: IconDrawable.swift, the auto-generated {FontName}Icon.swift and the font file added as a resource: Pod Setup

How to use

For complete documentation, visit Iconic's docs.

Import

Import the Iconic module:

Swift
import Iconic
Objective-C
@import Iconic;

Registering the icon font

Registration is required to activate Iconic. You shall do this once, when launching your application. Internally, the icon mapping is retrieved and kept in memory during the application's life term.

Iconic provides a convenient way to register the icon font: Note: the method name may change depending of your icon font's name:

Swift
FontAwesomeIcon.register()
Objective-C
[Iconic registerFontAwesomeIcon];

Use as images

You can construct an UIImage instance out of a font's icon and tint it. This may be very convenient for integrating with existing UIKit controls which expect UIImage objects already.

Images are created using NSStringDraw APIs to render a UIImage out of an NSAttributedString.

Swift
let size = CGSize(width: 20, height: 20)

let icon = FontAwesomeIcon.HomeIcon
let image = icon.image(ofSize: size, color: .blue)
Objective-C
[Iconic imageWithIcon:FontAwesomeIconHomeIcon size:CGSizeMake(20, 20) color:[UIColor blueColor]];

Use as attributed strings

You may need to icons as text too, and simplify your layout work. For example, instead of having an image and a label, you can combined it all in one single label:

Swift
let icon = FontAwesomeIcon.HomeIcon
let iconString = icon.attributedString(ofSize: 20, color: .blue)
Objective-C
[Iconic attributedStringWithIcon:FontAwesomeIconHomeIcon pointSize:20.0 color:[UIColor blueColor]];

Use as unicode string

Ultimately, you may need to retrieve the unicode string representation on an icon to do more advanced things:

Swift
let unicode = FontAwesomeIcon.HomeIcon.unicode

Use as font

For further customization, you may need to use the UIFont object instead:

Swift
let font = FontAwesomeIcon.font(ofSize: 20)
Objective-C
UIFont *font = [Iconic fontAwesomeIconFontOfSize:20.0];

Interface Builder Support

Interface Builder

Iconic includes a UIImageView subclass under the name of {FontName}IconView.swift, conforming to @IBInspectable. This class allows IB integration with little effort:

  • Use the iconName attribute to set the icon on Interface Builder (use the icon font html catalog as reference for icon names).
  • Adjust the bounds of the view to see it dynamically adjust the icon size.

UIKit Extensions

UIKit extensions are also included, just to make your code look simpler:

Swift
// UITarbBarItem
UITabBarItem(withIcon: .BookIcon, size: CGSize(width: 20, height: 20), title: "Catalog")

// UIBarButtonItem
UIBarButtonItem(withIcon: .BookIcon, size: CGSize(width: 24, height: 24), target: self, action: #selector(didTapButton))

// UIButton
let button = UIButton(type: .System)
button.setIconImage(icon: .HeartIcon, size: CGSize(width: 44, height: 44), color: nil, forState: .Normal)
Objective-C
// UITarbBarItem
[[UITabBarItem alloc] initWithIcon:FontAwesomeIconBookIcon size:CGSizeMake(20.0, 20.0) title:@"Catalog"];

// UIBarButtonItem
[[UIBarButtonItem alloc] initWithIcon:FontAwesomeIconCogIcon size:CGSizeMake(24.0, 24.0) target:self action:@selector(didTapButton)];

// UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setIconImageWithIcon:FontAwesomeIconHeartIcon size:CGSizeMake(44.0, 44.0) color:nil forState:UIControlStateNormal];

Sample Project

Check out the sample project, everything is demo'd there. Sample Project

Give Iconic a test drive by simply doing pod try Iconic in your terminal, and pick the Samples.xcworkspace.

On the sample project, Iconic is installed as a development pod. Because of this, pod files are not versioned. Therefore, if you clone the repo manually, you will to install the pods yourself.

About watchOS support:

When running the watchOS example, you might get a "No such module CoreText" error. This is because the CoreText.framework is missing for the watchOS Simulator. Run the 'WatchSimulator-CoreText-Patch.sh' script located in this repository, to copy the CoreText header files from the WatchOS SDK. You will then be able to run the watchOS sample with no issues as well as running Iconic on your Watch apps in the simulator.

Icon Font Catalog

Besides the auto-generated Swift code, an icon font catalog will be added in Pods/Iconic/Source/Catalog. Use this as a visual reference about the icons and their names.

Icon Font Catalog

Note: if you are using Chrome as your default browser, you will need to restart it using the open -a 'Google Chrome' --args -allow-file-access-from-files in the command line to be able to open view the catalog. This is because the html's javascript loads a local json file and Chrome has built-in security features to disable it. You can also use any other web browser like Safari or Firefox to open the catalog html.

Icon Font Samples

This repository also includes a few open source and free icon fonts for you to try Iconic with:

Acknowledgements

Iconic was originally developed by Ignacio Romero Zurbuchen. For more credits, please see AUTHORS.md.

License

This library is licensed under the Apache 2.0 license.

SwiftGen is licensed under the MIT License.

The Font Awesome font is licensed under the SIL OFL 1.1 License

Comments
  • Getting 'No Icon found'

    Getting 'No Icon found'

    I created a font using fontastic.me, installed with the .ttf file and all the SwiftGen generated Icon file has is import UIKit and a comment that says 'No Icon found'. I've tried it using FontAwesome's .ttf file and it works properly. Is there something I'm missing when creating the font or installing the pod?

    bug 
    opened by enzosv 27
  • Add support for brew

    Add support for brew

    Hey dzenbot! I am currently working on second project where I want to use Iconic, but we have a small issue. As Pods (in our experience) increase build time, we decided to move to Carthage instead. Here comes the problem, Iconic is only available through Pods and it does not seems right to use Pods together with Carthage. We also use SwiftGen on this project and it has this nice command line interface so it can be used in build phase run script.

    Is there any plan to implement CLI and then distribute Iconic with brew? Would be killer feature for us :-)

    enhancement help wanted 
    opened by josefdolezal 15
  • Error registering / unregistering font file.

    Error registering / unregistering font file.

    Hey. Cool project.

    Everything was working great for about 2 weeks, then I started getting this error:

    Error Domain=com.apple.CoreText.CTFontManagerErrorDomain Code=105 "Could not register the font file(s)"

    So, I checked out error code 105 -> kCTFontManagerErrorAlreadyRegistered

    I looked through Iconic's source and it doesn't look like the "already registered" case was handled, so I thought I'd just handle it myself in the app delegate by unregistering the font first:

    let bundle = NSBundle(forClass: Iconic.self)
    if let url = bundle.URLForResource("Linearicons", withExtension: "ttf"){
           var error: Unmanaged<CFErrorRef>? = nil
           CTFontManagerUnregisterFontsForURL(url, .None, &error)
           Iconic.registerIconFont()
    }
    

    However, the call to CTFontManagerUnregisterFontsForURL also returns an error:

    Error Domain=com.apple.CoreText.CTFontManagerErrorDomain Code=201 "Could not unregister the font file(s)"

    So, I checkout out error code 201 -> kCTFontManagerErrorNotRegistered

    Not registered... o.O

    Have you run into this before - not being able to register nor unregister a font? Tried cleaning, deleting my derived data, deleting the simulator's data, and double checked the font urls, but no luck.

    Could Iconic try to continue its initialization in the case when the error is 105 - already registered?

    Any suggestions appreciated.

    Thanks!

    bug 
    opened by salisbbn 11
  • Add robbiet480 as co-owner of CocoaPod to allow pushes

    Add robbiet480 as co-owner of CocoaPod to allow pushes

    @dzenbot mind adding me as a co-owner of the CocoaPod so I can push new versions? Should just need to run pod trunk add-owner Iconic [email protected] to get it done. You will remain an owner. Thanks

    opened by robbiet480 10
  • Updating pod predownload to default for every pod update.

    Updating pod predownload to default for every pod update.

    Hey, I know this library is in beta but I still want to use it. It seems that every time I need to update my pod file I have to point out the location for my font file, which then takes some time until it regenerate the Icon class, more than that if I'm doing plain pod update it installs Iconic with the default Icon class and removes mine..

    Is there a better workflow for this?

    opened by shshalom 8
  • how to generate multiple fonts?

    how to generate multiple fonts?

    looks like we can only generate one font at a time because the source directory is override everytime. Wondering if the iconizer.sh can take a font directory (FONT_DIR) environment variable, in addition to the FONT_PATH, to generate for all the *.ttf files found in the directory?

    opened by connectdotz 7
  • Rebuild using bitcode error

    Rebuild using bitcode error

    I get this error when trying to compile my app to my device.

    "/Users/johnrehbein/Library/Developer/Xcode/DerivedData/FlipBook-dvfxorfebyxoypbxslfercvccsye/Build/Products/Debug-iphoneos/Iconic/Iconic.framework/Iconic' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64"

    I'm not really sure how to rebuild this framework, so an update would be nice. For now I've just disabled bitcode in my app.

    opened by N7Alpha 6
  • multi-font + swifty

    multi-font + swifty

    addressing #23, #24, #2 and maybe #13 (although haven’t thoroughly tested yet).

    outline changes:

    1. Updated Iconizer.sh and the stencil files in order to generate multiple fonts without name collision and support the refactoring below.
    2. refactor the Iconic.swift and stencils to generate more swifty code that better align with swift3 API guideline: guideline: 2.1. move most of the logic from Iconic.swift to the new protocol "IconFont" 2.2. Iconic class is now a placeholder to house the generated wrapper functions for objective-c compatibility (since they can't access enum extension and protocol). 2.3 the UI extensions become just thin wrappers around the powerful swift enum mainly for objective-c access. (note: Samples/Pods/Iconic/Source/FontAwesomeIcon.swift is generated from the new stencil/Iconizer.sh)
    3. chnage catalog location and hierarchy in code generation to accomendate multi-font.
    4. Changed Sample swift controllers to use the new style API.
    5. Adjust unit tests accordingly; I did disable the UI extension tests since they are now nothing more than generated wrappers on the enum class that have already been tested in other 2 unit tests. The UI extensions are also exercised in both swift and objective-c controllers in the Sample project and they worked fine.
    opened by connectdotz 5
  • Swift 5 compatibility (and enum exhaustive check timeout) #87

    Swift 5 compatibility (and enum exhaustive check timeout) #87

    Resolves #87 Added a default case handler, and because the return type is not optional and we cannot throw inside a computed var it just does fatalError() with a message of where. Assuming we never had this before and it IS exhaustive, the compiler just doesn't know it - it won't be an issue.

    Bumped swift to 5.0 without any other changes to remove compiler warning. Perhaps @robbiet480 is suitable reviewer?

    Edit: This has been tested with a clean branch install and generates without issue or compiler warning in Xcode 11.3 and cocoa pods 1.8.4

    cla-signed cla-error 
    opened by mitchins 4
  • UIImageView property

    UIImageView property

    Hello guys,

    If I want to use UIImageView properties with UIImage coming from iconic font, for example how can I set UIImageView mode to Aspect Fit and get the size of the font adjust with the size of the imageView ?

    Thanks best regards

    question 
    opened by qclmnt 4
  • Optimizing compiler check on some variables

    Optimizing compiler check on some variables

    The compiler fails to check how exhaustive some switches are with the warning "The compiler is unable to check that this switch is exhaustive in reasonable time".

    The easiest solution is to add a default to these switch statements, to trick the compiler.

    Fix https://github.com/home-assistant/Iconic/issues/87

    cla-signed 
    opened by dzenbot 3
Releases(1.5)
Owner
Home Assistant
Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts.
Home Assistant
Icons fonts for iOS (Font Awesome 5, Iconic, Ionicon, Octicon, Themify, MapIcon, MaterialIcon, Foundation 3, Elegant Icon, Captain Icon)

Installation SPM Not yet supported. Please use Cocoapods or Carthage Carthage github "0x73/SwiftIconFont" Cocoapods CocoaPods is a dependency manager

sedat çiftçi 1.1k Dec 14, 2022
OS font complements library. Localized font supported.

SwiftFontName SwiftFontName is font name complements and supports localized font library. You don't need to search font name any more with SwiftFontNa

Morita Naoki 114 Nov 3, 2022
Font management (System & Custom) for iOS and tvOS

UIFontComplete Font management (System & Custom) for iOS and tvOS Usage No more wasted time searching for names of UIFont fonts and no more surprises

Nicholas Maccharoli 1.3k Nov 14, 2022
Font Awesome swift library for iOS.

Font Awesome Swift Follow me: @vaberer I like ★. Do not forget to ★ this super convenient library. Added UISegmentedControl & UITabbarItem & UISlider

Patrick Vaberer 746 Dec 17, 2022
🎢 Swift Library for Font Icons

Swift Library for Font Icons Please ★ this library. Now, you don't have to download different libraries to include different font icons. This SwiftIco

Saurabh Rane 781 Dec 6, 2022
Google Material Design Icons Font for iOS

GoogleMaterialDesignIcons #Google Material Design Icons Font for iOS It is based on https://github.com/google/material-design-icons. it converts the m

Yuji Hato 365 Oct 19, 2022
This projects shows how we can server-side add/update "ANY" custom font in a live iOS App without needing to update the app.

Server-side-Dynamic-Fonts This projects shows how we can server-side add/update "ANY" custom font in a live iOS App without needing to update the app.

null 2 Mar 26, 2022
OpenSansSwift - Easily use the OpenSans font in Swift.

OpenSansSwift Easily use the OpenSans font in Swift. Why use OpenSansSwift frameworks ? The usual process of embedding any custom fonts in your IOS ap

Hemant Sapkota 42 Jan 29, 2022
SwiftUIFontIcon The easiest way to implement font icons in your SwiftUI project.

SwiftUIFontIcon The easiest way to implement font icons in your SwiftUI project. Usage The library is super super easy to use, just something like thi

Bui Dac Huy 81 Dec 27, 2022
Font Awesome support in Swift

MCFontAwesome Font Awesome v4.1.0 for Swift Font aliases has not been ported yet, in order to refer to a font you have to strip all the - (minus) insi

Matteo Crippa 19 Jun 9, 2020
Generator of settings icon by SF Symbols. Customisable background color and ready-use in table cell.

SPSettingsIcons Generate settings icons by Apple's SF Symbols. For safe using SFSymbols see SPSafeSymbols library. Installation Swift Package Manager

Sparrow Code 110 Dec 28, 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
round icon drag control (made in swift) dock style

ASBubbleDrag Bubble drag control integrate in storyboard : Installation CocoaPods You can use CocoaPods to install ASBubbleDrag by adding it to your P

Alberto Scampini 46 Oct 12, 2022
Programmatically load custom fonts into your iOS and tvOS app.

FontBlaster Programmatically load custom fonts into your iOS and tvOS app. About Say goodbye to importing custom fonts via property lists as FontBlast

Arthur Ariel Sabintsev 1.1k Jan 3, 2023
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
Google Material Design Icons for Swift and ObjC project

GoogleMaterialIconFont Google Material Design Icons for Swift and ObjC project This library is inspired by FontAwesome.swift Both Swift and Objctive-C

Yusuke Kita 146 Nov 8, 2022
Pretendard Fonts for iOS (Swift Package Manager)

PretendardKit Pretendard 1.3.3 을 기반으로 합니다. Install (Swift Package Manager) dependencies: [ .package(url: "https://github.com/wookeon/PretendardKit

Darth Vader 1 Jun 2, 2022
Icon font library for iOS. Currently supports Font-Awesome, Foundation icons, Zocial, and ionicons.

FontAwesomeKit Icon font library for iOS. Currently supports Font-Awesome, Foundation icons, Zocial, and ionicons. Version 2.2 Notable Changes Not Jus

Pride Chung 2.8k Jan 6, 2023
Icons fonts for iOS (Font Awesome 5, Iconic, Ionicon, Octicon, Themify, MapIcon, MaterialIcon, Foundation 3, Elegant Icon, Captain Icon)

Installation SPM Not yet supported. Please use Cocoapods or Carthage Carthage github "0x73/SwiftIconFont" Cocoapods CocoaPods is a dependency manager

sedat çiftçi 1.1k Dec 14, 2022
OS font complements library. Localized font supported.

SwiftFontName SwiftFontName is font name complements and supports localized font library. You don't need to search font name any more with SwiftFontNa

Morita Naoki 114 Nov 3, 2022