Font Awesome swift library for iOS.

Overview

Font Awesome Swift

Font Awesome Swift

Follow me: @vaberer

I like ★. Do not forget to ★ this super convenient library.

Added UISegmentedControl & UITabbarItem & UISlider & UIStepper & UITextField support!

Font Awesome swift library for iOS. No image icons any more. Using Font Awesome Swift library is very easy to use. Look at the demo app which shows all icons and their names or just visit FontAwesome.

Requirements

  • iOS 8.0+
  • Xcode 8

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

To integrate Font Awesome Swift into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Font-Awesome-Swift', '~> 1.7.2'

Then, run the following command:

$ pod install

Do not forget to import to your swift files where you want to use this library:

import Font_Awesome_Swift

Check branches swift-2.2, swift-2.3 or swift-3

Manually

  1. Copy FAIcon.swift and FontAwesome.ttf files into your project
  2. Check to import FontAwesome.ttf in project, "Project" > "Target" > "Copy Bundle Resources"

Usage

Super easy way how to add an icon.

UIImage

For Stacked images, please refer Stacked Icons

    UIImage.init(icon: .FATwitter, size: CGSize(width: 35, height: 35))
    
    // Change colors
    UIImage.init(icon: .FATwitter, size: CGSize(width: 35, height: 35), textColor: .red, backgroundColor: .black)
    
    // Stacked Images With Bigger Background
    UIImage.init(bgIcon: .FASquareO, bgTextColor: .white, topIcon: .FATwitter, topTextColor: .white, bgLarge: true)
    UIImage.init(bgIcon: .FACircle, bgTextColor: .black, topIcon: .FAFlag, topTextColor: .white, bgLarge: true)
    
    // Stacked Images With Smaller Background
    UIImage.init(bgIcon: .FACamera, bgTextColor: .black, topIcon: .FABan, topTextColor: .red, bgLarge: false)

    // Stacked Images With Bigger Background and Custom Size
    UIImage.init(bgIcon: .FASquare, bgTextColor: .black, topIcon: .FATerminal, topTextColor: .white, bgLarge: true, size: CGSize(width: 50, height: 50))

UIImageView

    imageView.setFAIconWithName(icon: .FATwitter, textColor: .blue, backgroundColor: .gray)

    imageView.setFAIconWithName(icon: .FATwitter, textColor: .blue)
    

UILabel

    labelName.FAIcon = .FAGithub

    labelName.setFAIcon(icon: .FAGithub, iconSize: 35)

    labelName.setFAText(prefixText: "follow me on ", icon: .FATwitter, postfixText: ". Thanks!", size: 25)

    // Bigger icon:
    labelName.setFAText(prefixText: "follow me on  ", icon: .FATwitter, postfixText: ". Thanks!", size: 25, iconSize: 30)

    labelName.setFAColor(.red)
    

UIButton

    buttonName.setFAIcon(icon: .FAGithub, forState: .normal)

    // Set icon size
    buttonName.setFAIcon(icon: .FAGithub, iconSize: 35, forState: .normal)

    buttonName.setFAText(prefixText: "follow me on ", icon: .FATwitter, postfixText: ". Thanks!", size: 25, forState: .normal)

    // Bigger icon
    buttonName.setFAText(prefixText: "follow me on ", icon: .FATwitter, postfixText: ". Thanks!", size: 25, forState: .normal, iconSize: 30)

    // Change color:
    buttonName.setFATitleColor(color: .red, forState: .normal))
    

UIBarButtonItem

    // Standard font size
    barName.FAIcon = .FAGithub

    // Custom font size
    barName.setFAIcon(icon: .FAGithub, iconSize: 35)

    barName.setFAText(prefixText: "follow me on ", icon: .FATwitter, postfixText: ". Thanks!", size: 25)

    barName.tintColor = .red

UITextField

    // Right View Icon
    textfield.setRightViewFAIcon(icon: .FASearch, rightViewMode: .always, textColor: .red, backgroundColor: .clear, size: nil)

    // Left View Icon
    textfield.setLeftViewFAIcon(icon: .FAPlus, leftViewMode: .always, textColor: .red, backgroundColor: .clear, size: nil)

UISegmentedControl

  segmentedControl.setFAIcon(icon: .FATwitter, forSegmentAtIndex: 0)
  

UIStepper

    stepper.setFABackgroundImage(icon: .FAGithub, forState: .normal)
    stepper.setFAIncrementImage(icon: .FABellO, forState: .normal)
    stepper.setFADecrementImage(icon: .FABellSlashO, forState: .normal)
    

UITabbarItem

  tabBarController?.tabBar.items?.first?.setFAIcon(.FATwitter)
  
  // Options to change selected and unselected color
  tabBarItem.setFAIcon(icon: .FATwitter, size: nil, textColor: .red, backgroundColor: .black, selectedTextColor: .yellow, selectedBackgroundColor: .white)
  
  // Options to change selected and unselected color with specific size
  tabBarItem.setFAIcon(icon: .FATwitter, size: CGSize(width: 35, height: 35), textColor: .red, backgroundColor: .black, selectedTextColor: .yellow, selectedBackgroundColor: .white)
  

UISlider

  // Change minimum or maximum value image
  slider.setFAMinimumValueImage(icon: .FABellSlashO)
  slider.setFAMaximumValueImage(icon: .FABellO)

  // change minimum or maximum value image with a specific size
  slider.setFAMinimumValueImage(icon: .FABellSlashO, customSize:  CGSize(width: 35, height: 35))
  slider.setFAMaximumValueImage(icon: .FABellO, customSize:  CGSize(width: 35, height: 35))
  

UIViewController

  // Change navigation title
  FATitle = .FATwitter
  

Author

Patrik Vaberer, [email protected]

Licence

Font Awesome Swift is available under the MIT license. See the LICENSE file for more info.

Comments
  • Bottom part of text cut off

    Bottom part of text cut off

    I'm new to iOS programming. I've noticed that if I have a prefix containing the letters "g", "p", etc, the bottom part of the text is cut off when I use font awesome icons.

    Imgur

    Is there a workaround to that? That's Swiftybutton by the way.

    opened by squeeish 5
  • Create UIImage from FontAwesome icon

    Create UIImage from FontAwesome icon

    Hi

    I made a simple extension of your library. It is based on UIImage support in project: https://github.com/thii/FontAwesome.swift/blob/master/FontAwesome/FontAwesome.swift

    Could you integrate it and release new version, please?

    opened by marekmatula 5
  • Color on FAIcons

    Color on FAIcons

    Hi Patrik,

    was wondering if it's possible to use colors on the icons? Haven't worked that much with FA, but I'm not sure if it's at all possible... would be really nice, though.

    opened by BasThomas 5
  • UIBarButtonItem position

    UIBarButtonItem position

    This library is awesome just like the font... but when I use it with a UIBarButtonItem the icon seems not to be aligned vertically with the title of the UINavigationBar and also very close from the boundary of the screen

    opened by Casporro 5
  • fatal error: unexpectedly found nil while unwrapping an Optional value

    fatal error: unexpectedly found nil while unwrapping an Optional value

    in class FontLoader line 324:

    fontURL = bundle.URLForResource(FAStruct.FontName, withExtension: "ttf", subdirectory: "Font-Awesome-Swift.bundle")!

    just updated (pod install) and pod installed version 1.4.6

    updated to version 1.4.8 and still have the issue. for some weird reason still pointing to line 324 but there are no code there.. I cleaned up and build the project.. simple don't understand.

    opened by mhermosi 4
  • Updated Font Awesome to 4.6.3 & created crude update tool

    Updated Font Awesome to 4.6.3 & created crude update tool

    Tested the new & old to make sure it is all working.

    Font Awesome has been updated from 4.4 to 4.6.3.

    I've made sure Aliases are included (after initially forgetting) and that the class names have remained the same for the sake of not breaking current installations, although if there is a mismatch - let me know! I could have missed one whilst checking.

    The tool is just a simple script I wrote to pull and format the class names and unicode codes to try to make updating a little more painless, take from it what you will. It uses the YAML data from the official repo, what they use to generate the FontAwesome icon gallery page, parses and formats the data and just echoes the strings out.

    opened by othyn 4
  • UIButton Title Color not working in 1.4.3

    UIButton Title Color not working in 1.4.3

    Found out that 1.4.3 has the ability to set the UIButton font to another font rather than system font, which is awesome.

    However, also found out that cannot set the title color of the button anymore in 1.4.3 (defaulting to black), reverting back to 1.4.2 fixes it.

    Will check whether I can fix this.

    opened by alvinnguyen 3
  • Problem when tap a button a change state to selected

    Problem when tap a button a change state to selected

    I have a UIButton with FAHeartO for state .Normal and FAHeart for state selected but when I change the state to selected at user taps the button the colors change. If I have a normal button whit tintColor set to redColor in normal state but the selected estate shows the FAHeart in whiteColor and the background in redColor. I need the FAHeart in redColor with clearColor in the background. Is this a bug?

    opened by Casporro 3
  • Sets FAIcon on UIBarButtonItem selected state

    Sets FAIcon on UIBarButtonItem selected state

    Before this change when you would press a UIBarButtonItem that had an FAIcon, the icon would switch to a question mark with a box around it for unknown character.

    I just added the titleTextAttributes change for the selected state and now it works how I would expect it to.

    opened by adam-casey 2
  • Setting FA Icon on 5th UITabbarItem causes NSException

    Setting FA Icon on 5th UITabbarItem causes NSException

    Great library - thanks! (new to Swift/iOS, though been using FA icons for many projects - glad to use them for latest one!)

    Question is on setting the icon for tabs when you have more than 5.

    Setting each was simple enough (the documentation states to use 'first', though we found we can do this for each one...) ` tabBarController?.tabBar.items?[0].setFAIcon(icon:.FAUser)

        tabBarController?.tabBar.items?[1].setFAIcon(icon:.FAUser)
    
        tabBarController?.tabBar.items?[2].setFAIcon(icon:.FAUser)
    
        tabBarController?.tabBar.items?[3].setFAIcon(icon:.FAUser)
    
        tabBarController?.tabBar.items?[4].setFAIcon(icon:.FAUser)
    

    ` Works great - IF you have only 5 tabs........

    However, if you have a 6th tab, [4] no longer works....

    When setting a 6th (or more) tab, iOS changes "#5" to "More" with a ... 'icon' and then the user can select which one they want (and also the user can arrange the tabs - not highly useful in our app, but a cool feature, I guess..)

    So, this does NOT work..... (

    tabBarController?.tabBar.items?[X].setFAIcon(icon:.FAUser) (where 'X' is 5 or more)

    Doing so get an error because the array is only 5 long.....

    *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 5 beyond bounds [0 .. 4]'

    How to set the icons as FA Icons for these 'More' tabs?

    opened by TCOA 2
  • UITabBarItem color options not working

    UITabBarItem color options not working

    This works fine:

        let tabBarItem = self.tabBarController?.tabBar.items?.first
        tabBarItem?.setFAIcon(icon: .FABell)
    

    The tab icon FABell icon appears.

    But the image and text color is blue even though the defaults to the setFAIcon method are black.

    Passing a value for the selected selectedTextColor and other color properties do not seem to have any affect on the color.

    How can you change the color? Are we doing something incorrectly?

    Thanks

    opened by marcusleon 2
  • update setFAIcon params

    update setFAIcon params

    I had some error about name of some params and I rename theme like : UITextFieldViewMode => UITextField.ViewMode UIImageOrientation => UIImage.Orientation

    and some others

    opened by siempay 3
  • SwiftUI support

    SwiftUI support

    struct Fontawesome: View {
        var fa: FAType
        
        var body: some View {
            Text(fa.text!).font(getfont())
        }
        
        func getfont() -> Font {
            FontLoader.loadFontIfNeeded()
            return Font.custom(FAStruct.FontName, size: 18)
        }
    }
    
    struct ContentView: View {
        var body: some View {
            VStack {
                
                Fontawesome(fa: FAType.faAdjust).foregroundColor(Color.green)
                
                Text("Hello, World!")
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
            }
        }
    }
    
    
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView()
        }
    }
    
    opened by snaill 0
  • Removed the Selected state and replaced it through highlighted at the…

    Removed the Selected state and replaced it through highlighted at the…

    … right places

    On iOS9 and up you are still running into the terminal warning

    [Assert] button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted, UIControlStateDisabled and UIControlStateFocused. state = 4 is interpreted as UIControlStateHighlighted.
    

    Removing the .selected State and replacing it through .highlighted solves the problem.

    opened by patreu22 2
Owner
Patrick Vaberer
iOS Engineer -good to great-
Patrick Vaberer
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
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
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
Auto-generated icon font library for iOS, watchOS and tvOS

Iconic helps making icon fonts integration effortless on iOS, tvOS and watchOS. Its main component is in charge of auto-generating strongly typed Swif

Home Assistant 1.6k Nov 12, 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
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
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
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
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
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
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 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
Use Ionicons in your Swift projects.

IoniconsKit IoniconsKit internally use ionicons.ttf v2.0.1 Example To run the example project, clone the repo, and run pod install from the Example di

Keita Oouchi 313 Dec 8, 2022
Use Octicons in your Swift projects.

OcticonsKit OcticonsKit internally use octicons.ttf v4.3.0 Example To run the example project, clone the repo, and run pod install from the Example di

Keita Oouchi 52 Jan 31, 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
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