How to use Font Awesome in Swift - Clearly Innovative | Web and Mobile DevelopmentClearly Innovative | Web and Mobile Development

images

 

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

    and wire it to the storyboard
  5. Here’s the important part. In viewDidLoad, set the label’s text to the following unicode:

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/

See the complete Swift Project Here https://bitbucket.org/ClearlyInnovative/blog-post-swift-fontawesome/