Skip to content

UITabBar ​

UITabBar 表示标签控制器屏幕底部的那一排标签。它里面有哪几个标签,由标签控制器的 viewControllers 和每个页面的 tabBarItem 决定。这个类只用来改标签的颜色。

它是一个视图,但不要往它上面加子视图,也不要改它的 frame。

继承关系:EventTarget → NSObject → UIResponder → UIView → UITabBar

构造函数 ​

不能用 new 创建。new UITabBar() 抛 TypeError: Illegal constructor: UITabBar is created by the runtime, not by new。从标签控制器的 tabBar 读。

实例属性 ​

还继承 UIView 的属性。

属性说明
tintColor选中的标签的颜色
unselectedItemTintColor没选中的标签的颜色

示例 ​

js
const tabs = new UITabBarController();
tabs.tabBar.tintColor = 'systemPink';
tabs.tabBar.unselectedItemTintColor = 'systemGray';

效果:选中的标签(图标和文字)是粉色,其余的是灰色。颜色的实际效果未在模拟器验证,两个属性的读写核对过。

对应的 iOS API ​

ObjCJS
tabs.tabBar.tintColor = UIColor.systemPinkColortabs.tabBar.tintColor = 'systemPink'
tabs.tabBar.unselectedItemTintColor = UIColor.systemGrayColortabs.tabBar.unselectedItemTintColor = 'systemGray'

参见 ​