我设置了一个全局tintColor,我可以在界面构建器中看到它,当我选择UITabBar和UITabBarController时,仍然在运行应用程序时,所选UITabBarItem的色调是iOS默认值(蓝色),并且不是我设定的。我错过了什么?
P.S。 UITabBarController被推送到navigationController,它不是rootViewController
答案 0 :(得分:13)
故事板还没有直接支持。但您可以在故事板中设置用户定义的运行时属性。
选择身份检查器。 (您可以在其中设置视图类的视图。)
如果您想更改所选项目的色调,请改用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颜色。
在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的颜色。