A blog for technology, SEO tips, website development and open source programming.

How to use Font Awesome in Swift

2 3,933

Font awesome can be a useful part of any project. It comes with a set of common icons and image assets. Since you use text instead of images, you can customize the color and resize without pixellation. Common use cases include social media icons, button icons, camera and play button overlays, etc.

Integrating font awesome is as simple as integrating any other font.

  1. Create a new project
  2. Download font awesome from http://fortawesome.github.io/Font-Awesome/
  3. Unzip the folder and drag fonts/fontawesome-webfont.ttf into your project
  4. Open Supporting Files/Info.plist
    • Add a new key “Fonts provided by application”. This is of type Array.
    • Expand the array, and for Item 0, set the string value to “fontawesome-webfont.ttf”

Now that you have integrated font awesome into your project, try to create an icon.

  1. Drop a label on your storyboard
  2. Set the font to “Custom”, and the family to FontAwesome
  3. Set the font size to 40, and the color to Aqua
  4. Declare this in your view controller
    @IBOutlet weak var fontAwesomeIcon: UILabel!
    and wire it to the storyboard
  5. Here’s the important part. In viewDidLoad, set the label’s text to the following unicode:
    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    fontAwesomeIcon.text = “\u{f082}”
    }

The only tricky part is setting the unicode of the text label programmatically. For some reason, the unicode cannot be set in the storyboard nor the runtime attributes. This may be due to the unicode syntax in swift.

All of the unicode values are available on http://fortawesome.github.io/Font-Awesome/icons/

2 Comments
  1. lap says

    thanks for your help , and also you need add a slash before u{} like this. : fontAwesomeIcon.text = “\u{f082}”
    good luck

    1. Panayiotis Georgiou says

      Yes you are correct! Thanks..

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More