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

标签 ios swift uitabbar font-awesome swift2

我想在 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/

相关文章:

ios - 在带有 UITableView 的 UIViewController 中使用 UIRefreshControl

ios - 将 UIButton 作为 subview 添加到 UITabBar

iOS swift : add kern space in the tab bar text

iphone - Google 云端硬盘 SDK 和 iOS 5.1

ios - 在 UITabBar 项下添加 gif 动画

ios - 真正的随机 Xcode

arrays - 如何快速对 Range<Index> 的数组进行排序?

ios - 它总是在 iOS swift 中返回相同的索引 "picker.selectedRow(inComponent: 0)"

ios - 中心按钮标签栏

ios - 隐藏 UITableview 单元格