2014-11-22 54 views
2

我想改變所有應用程序的NavigationControl的後退按鈕的顏色,我該怎麼做?我想擁有它的紅色,而不是正常的藍色按鈕...快速改變NavigationControl和TabBar的顏色

我必須跟我的TabBar的問題。 我已經改變了從標準的藍色圖標的顏色和名稱爲紅色與這些:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState:.Selected) 

class TabBarController: UITabBarController { 

var color = UIColor.redColor() 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    self.tabBarController?.tabBar.selectedImageTintColor = UIColor.redColor() 
    UITabBar.appearance().selectedImageTintColor = UIColor.redColor() 

但我有超過5個標籤,所以我有按鈕「更多」,當我按下它時,圖標不是紅色,而是藍色,而當我按下編輯標籤欄圖標時,標籤的名稱爲紅色,但圖標不是。 我能做什麼? 圖片說明: http://postimg.org/image/67oqa15ll/

回答

1

試試這個在您的firstViewController

class ViewController: UIViewController,UITabBarDelegate, UITabBarControllerDelegate, UINavigationControllerDelegate { 

     override func viewDidLoad() { 
      super.viewDidLoad() 

      UITabBar.appearance().tintColor = UIColor.redColor() 
      var view: UITableView = self.tabBarController?.moreNavigationController.topViewController.view as UITableView 
      view.tintColor = UIColor.redColor() 
      if view.subviews.count != 0 { 
       for cell in view.visibleCells() { 
        cell.textLabel??.textColor = UIColor.redColor() 
       } 
      } 
     } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


} 

,這在你的UITabBarController

class TabbarViewController: UITabBarController,UITabBarDelegate, UITabBarControllerDelegate, UINavigationControllerDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Do any additional setup after loading the view. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    override func tabBar(tabBar: UITabBar, didBeginCustomizingItems items: [AnyObject]) { 
     self.view.tintColor = UIColor.redColor() 

    } 
} 

示例項目https://www.dropbox.com/s/kbm4l60cnvyrf5h/UItabbarCustomizing.zip?dl=0

我希望我幫你

+0

嘿,謝謝你的回答。你用NavigationController解決了我的問題,但是我也遇到了TabBar問題。在「更多」中,如何將圖標的顏色從藍色更改爲紅色?我怎樣才能讓它在更多的「編輯」頁面中起作用呢? – MatteoAB 2014-11-23 02:07:48

+0

謝謝你,它可以在tabBar上工作,但有一個「更多」選項卡的錯誤。當我按下它時,它會用我的其他選項卡和他們的圖標打開一張桌子,但問題是那裏的圖標不是紅色的,但它們仍然是藍色的......如何修復它? – MatteoAB 2014-11-24 12:38:08

+0

這就是我的問題:http://postimg.org/image/bcw1q66cp/顏色不能在更多的工作,但只在tabBar,而不是文本的作品。我希望所有的圖標都是紅色而不是藍色。 – MatteoAB 2014-11-24 13:43:08

7

要更改文本和圖標的顏色在整個應用程序的所有UITabBarItems(斯威夫特/ Xcode中6):

在AppDelegate.swift:

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

    // Override point for customization after application launch. 

    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: your_color ], forState: .Selected) 

    UITabBar.appearance().tintColor = your_color 

    return true 

} 

這將這樣的伎倆!

+0

它工作在tabBar中,但在「更多」部分中,其他圖標仍然是藍色的... – MatteoAB 2015-03-18 12:31:08

+0

在Swift 3.0中,而不是** forState :** 用於:**。 UIControlState.Selected也稍微改爲小寫:'UITabBarItem.appearance()。setTitleTextAttributes([NSForegroundColorAttributeName:your_color],for:.selected)' – vitalytimofeev 2017-03-20 07:53:57