2015-08-31 38 views
4

我想在FontAwesome Swift library中使用一些圖標作爲UITabBarItem圖像。我已經能夠設置UITabBarItem標題,但我無法設置UITabBarItem圖像。我的代碼如下:Swift:使用FontAwesome圖標作爲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'。有沒有辦法將一個字符串轉換爲UIImage還是有另一種方法來解決這個問題?

在此先感謝。

回答

6

每你聯繫上該庫中的自述:

currentItem.image = UIImage.fontAwesomeIconWithName(.Money, , textColor: UIColor.blackColor(), size: CGSizeMake(30, 30)) 

的功能,您使用的返回一個字符串,是用於圖標文本的快捷方式。這對於使用FontAwesome的標籤或按鈕文本很有用。你要做的是設置圖像 - 我會重新閱讀自述文件,並熟悉該庫的內置函數。

+0

謝謝,我想我應該讀一點這個庫。 – lmiguelvargasf

+0

他們有不錯的文檔!應該幫助很多希望。 –