Swift: 使用 FontAwesome 图标作为 UITabBarItem 图像

Swift: Use a FontAwesome icon as a UITabBarItem image

我想使用 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))

您使用的函数 returns 作为图标文本快捷方式的字符串。这对于使用 FontAwesome 的标签或按钮文本很有用。您要做的是设置图像 - 我会重新阅读自述文件,然后熟悉该库的内置函数。