I would like to use some icons in the FontAwesome Swift library as UITabBarItem images. I have been able to set the UITabBarItem title, but I am not able to set the UITabBarItem image. My code is as follows:
class AEVTabBarController: UITabBarController {
var itemLabels = ["Promos", "Marcas", "Amigos", "Cerca de mí", "Más"]
override func viewDidLoad() {
super.viewDidLoad()
let tabItems = self.tabBar.items as [UITabBarItem]!
for index in 0..<itemLabels.count {
let currentItem = tabItems[index] as UITabBarItem
currentItem.title = itemLabels[index]
currentItem.image = String.fontAwesomeIconWithName(FontAwesome.Money) as UIImage
}
}
}
What the compiler is telling me is that 'String' is not convertible to 'UIImage'. Is there a way to convert a String into a UIImage or is there another way to solve this?
Thanks in advance.
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.
The font-awesome icon can be placed by using the fa prefix before the icon's name. Example: In this example, we will take a form where the input field is necessary. After that, we will place the font-awesome icon inside the input field. We will use the CDN link to use the font-awesome icons.
Per the readme on that library you linked:
currentItem.image = UIImage.fontAwesomeIconWithName(.Money, , textColor: UIColor.blackColor(), size: CGSizeMake(30, 30))
The function you used returns a string that is the text shortcut for the icon. This would be useful for a label or button text that's using FontAwesome. What you're trying to do is set the image - I would re-read the Readme, and just get acquainted with the built in functions of that library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With