我是新手,请有人帮我吗?
我尝试在应用程序委托中添加外观tintcolor,但我的构想已耗尽,这是行不通的
let myTabBar = UITabBar()
myTabBar.tintColor = UIColor.green
if #available(iOS 10.0, *) {
myTabBar.unselectedItemTintColor = UIColor.red
}
let one = UITabBarItem()
one.title = "Home"
one.tag = 1
one.image = UIImage(named: "home")
myTabBar.delegate = self
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
switch item.tag {
case 1:
let controller = businessStoryboard.instantiateViewController(withIdentifier: "BusinessListViewController")
addChildViewController(controller)
view.addSubview((controller.view)!)
controller.didMove(toParentViewController: self)
break
default:
break
}
}
答案 0 :(得分:0)
您需要从UITabBarController
获取tabBar,然后更改tint属性,类似这样,假设您的rootViewController是UITabBarController
if let tabBarController = self.window?.rootViewController as? UITabBarController {
self.configureTabBar(tabBarController:tabBarController)
}
func configureTabBar(tabBarController: UITabBarController) {
// Tab bar customization
tabBarController.tabBar.tintColor = UIColor.red
}