我想在 FontAwesome Swift library 中使用一些图标作为 UITabBarItem 图像。我已经能够设置 UITabBarItem 标题,但我无法设置 UITabBarItem 图像。我的代码如下:
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
}
}
}
编译器告诉我的是“String”不能转换为“UIImage”。有没有一种方法可以将 String 转换为 UIImage 或者是否有另一种方法来解决这个问题?
提前致谢。
最佳答案
根据您链接的那个库的自述文件:
currentItem.image = UIImage.fontAwesomeIconWithName(.Money, , textColor: UIColor.blackColor(), size: CGSizeMake(30, 30))
您使用的函数返回一个字符串,它是图标的文本快捷方式。这对于使用 FontAwesome 的标签或按钮文本很有用。您要做的是设置图像 - 我会重新阅读自述文件,然后熟悉该库的内置函数。
关于ios - Swift:使用 FontAwesome 图标作为 UITabBarItem 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32321349/