Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use font awesome icons in swift?

I use this code but icon is no displayed and it shows me like this

i.stack.imgur.com/hPEPs.png

medicalpacakgesbutton.setTitle("\u{f0c3}", for: .normal)
like image 675
Ansar Iqbal Avatar asked Jan 04 '18 11:01

Ansar Iqbal


People also ask

How do I use awesome font icons?

You can place Font Awesome icons just about anywhere using the CSS Prefix fa and the icon's name. Font Awesome is designed to be used with inline elements (we like the <i> tag for brevity, but using a <span> is more semantically correct). icon If you change the font-size of the icon's container, the icon gets bigger.

How do I use Font Awesome 5 icons?

To use the Free Font Awesome 5 icons, you can choose to download the Font Awesome library, or you can sign up for an account at Font Awesome, and get a code (called KIT CODE) to use when you add Font Awesome to your web page.


1 Answers

The best way to use Font Awesome in your app is FontAwesome.Swift

Example for a button icon:

button.titleLabel?.font = UIFont.fontAwesome(ofSize: 30)
button.setTitle(String.fontAwesomeIcon(name: .coffee), for: .normal)

Or for a tab bar icon:

let image = UIImage.fontAwesomeIcon(name: .coffee, textColor: UIColor.black, size: CGSize(width: 40, height: 40))
viewController.tabBarItem = UITabBarItem(title: "Coffee", image: image, tag: 1)
like image 67
sundance Avatar answered Oct 18 '22 10:10

sundance