2014-11-22 49 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