UITabBar tintColor没有改变故事板

时间:2014-07-10 07:23:56

标签: ios objective-c uitabbarcontroller uitabbar

我设置了一个全局tintColor,我可以在界面构建器中看到它,当我选择UITabBar和UITabBarController时,仍然在运行应用程序时,所选UITabBarItem的色调是iOS默认值(蓝色),并且不是我设定的。我错过了什么?

P.S。 UITabBarController被推送到navigationController,它不是rootViewController

4 个答案:

答案 0 :(得分:13)

故事板还没有直接支持。但您可以在故事板中设置用户定义的运行时属性

选择标签栏控制器的标签栏。 Select the tab bar of the tab bar controller.

选择身份检查器。 (您可以在其中设置视图类的视图。)

Select the identity inspector

如果您想更改所选项目的色调,请改用selectedImageTintColor密钥路径。

答案 1 :(得分:11)

didFinishLaunchingWithOptions:

appDelegate方法中使用此代码
 [[UITabBar appearance] setSelectedImageTintColor: [UIColor redColor]];

用您想要的颜色替换红色。

答案 2 :(得分:5)

如果您的目标是iOS 8,那么

  

在iOS 8中不推荐使用selectedImageTintColor使用tintColor

夫特

TwoWayGridView scrollview;
scrollview = (TwoWayGridView) findViewById(R.id.grid_viewlevel);
mAdapter = new LevelAdapter(this, R.layout.levelselect);
scrollview.setAdapter(mAdapter);

目标c

    UITabBar.appearance().tintColor = UIColor.redColor()

答案 3 :(得分:0)

在我的应用程序中,我希望每个ViewController在显示时都具有唯一的TabBarItem颜色。

enter image description here

在iOS 8中,在故事板中手动添加tintColor属性工作正常,但在iOS 9 / Xcode 8下不再有任何效果。

我通过在每个TabBarController的子ViewControllers中包含以下代码解决了这个问题,覆盖了每个ViewDidAppear()函数。

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    self.tabBarController?.tabBar.tintColor = UIColor.whateverColor
    //The rest of your code
}

这在任何ViewController中都是安全的,因为?在tabBarController调用之后。如果ViewController没有嵌入TabBarController中,那么整个行都会被忽略。

通过在每个VC中放置此代码,您可以轻松指定每个TabBarItem的颜色。