Skip to content
Font Awesome Swift library for iOS. SPM (Swift Package Manager) version.
Swift
Branch: master
Clone or download
Pull request Compare This branch is 7 commits ahead of Vaberer:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.swiftpm/xcode/package.xcworkspace
Example/AF SwiftTests
FontToCopyInYourApp
Sources/FontAwesomeSwift
Tests
resources
.gitignore
.swift-version
LICENSE
Package.swift
README.md

README.md

Font Awesome Swift 5 with Swift Package Manager

This library forked from https://github.com/Vaberer/Font-Awesome-Swift , updated to Swift 5 and converted to SPM.

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 10.0+
  • Xcode 11

Installation

CocoaPods

No CocoaPods anymore thankfully.

Xcode 11 Install

  1. File->Swift Packages->Add Package Dependency...
  2. In the 'Chose Package Repository' popup window; copy/paste https://github.com/trevor-sonic/Font-Awesome-Swift.git repository full address into search field.
  3. Tap 'Next'
  4. Copy the 'FontAwesome.ttf' from 'FontToCopyInYourApp' into your app's buldle folder (as same level as AppDelegate.swift)

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

Original Author

Patrik Vaberer, patrik@toptal.com

Licence

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

You can’t perform that action at this time.