簡體   English   中英

更改圖標顏色選項卡欄控制器-SWIFT

[英]Change Icon Color Tab Bar Controller-SWIFT

我正在使用SWIFT在Xcode 6中進行操作,並且能夠成功更改標簽欄控制器上文本的顏色,但是我無法在圖標本身上更改顏色。 我在AppDelegate中的以下代碼:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: 239/255, green: 64/255, blue: 54/255, alpha: 1.0)], forState: .Selected)
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState: .Normal)

我有一個單獨的類,用於導航控制器來更改文本和顏色。

您需要將選項卡欄項上的image設置為UIImagerenderingMode = UIImageRenderingMode.AlwaysTemplate

然后,您可以在UITabBar上設置tintColor ,以同時更改圖標和文本的顏色。 不過,您仍然應該可以使用創建的外觀選擇器覆蓋文本的內容。

如果我還記得的話, UITabBar應該自動設置renderingMode ,所以嘗試先設置一下tintColor

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM