Use Font Awesome in your Swift projects
Since this is a Swift project, integrating using Carthage is the recommended way. Releases which support CocoaPods might be delayed sometimes.
To integrate FontAwesome into your Xcode project using Carthage, specify it in your Cartfile
:
github "code-troopers/FontAwesome4.swift"
Then add import FontAwesome4
to the top of the files using FontAwesome.
To integrate FontAwesome 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 'FontAwesome4.swift'
Then, run the following command:
$ pod install
And add import FontAwesome4_swift
to the top of the files using FontAwesome.
- Drag and drop
FontAwesome.otf
and all Swift files into your project
label.font = UIFont.fontAwesome4(ofSize: 100)
label.text = String.fontAwesome4Icon(name: .github)
label.font = UIFont.fontAwesome4(ofSize: 200)
label.text = String.fontAwesome4Icon(code: "fa-github")
button.titleLabel?.font = UIFont.fontAwesome4(ofSize: 30)
button.setTitle(String.fontAwesome4Icon(name: .github), for: .normal)
let attributes = [NSFontAttributeName: UIFont.fontAwesome4(ofSize: 20)] as [String: Any]
leftBarButton.setTitleTextAttributes(attributes, for: .normal)
leftBarButton.title = String.fontAwesome4Icon(name: .github)
let attributes = [NSFontAttributeName: UIFont.fontAwesome4(ofSize: 20)] as [String: Any]
toolbarItem.setTitleTextAttributes(attributes, for: .normal)
toolbarItem.title = String.fontAwesome4Icon(name: .github)
tabBarItem.image = UIImage.fontAwesome4Icon(name: .github, textColor: UIColor.black, size: CGSize(width: 30, height: 30))
tabBarItem.image = UIImage.fontAwesome4Icon(name: .github, textColor: UIColor.blue, size: CGSize(width: 4000, height: 4000), backgroundColor: UIColor.red)
iOS 8 or later.
- FontAwesome.otf file licensed under SIL OFL 1.1
- FontAwesome.swift licensed under MIT