繁体   English   中英

Swift:如何将图标图像和图像背景添加到 App 委托中的 UItabBar?

[英]Swift : How to add icon image and image background to the UItabBar in App delegate?

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

var nav1 = UINavigationController()
var first = ViewController(nibName: nil, bundle: nil)
nav1.viewControllers = [first]

var second = ccDiscovery(nibName: nil, bundle: nil)
var nav2 = UINavigationController()
nav2.viewControllers = [second]

var third = ccPosting(nibName: nil, bundle: nil)
var nav3 = UINavigationController()
nav3.viewControllers = [third]

var fourth = ccProfile(nibName: nil, bundle: nil)
var nav4 = UINavigationController()
nav4.viewControllers = [fourth]

var tabs = UITabBarController()
tabs.viewControllers = [nav1, nav2,nav3,nav4]

self.window!.rootViewController = tabs;
self.window?.makeKeyAndVisible();

如何将图标图像和图像背景添加到 App 委托中的UItabBar 我找不到任何。

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.magentaColor()], forState:.Normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState:.Selected)

UITabBarController项目在单独的视图控制器tabBarItem属性上设置:

var tabs = UITabBarController()
nav1.tabBarItem.image = UIImage(named: "some-image-1")
nav2.tabBarItem.image = UIImage(named: "some-image-2")
nav3.tabBarItem.image = UIImage(named: "some-image-3")
nav4.tabBarItem.image = UIImage(named: "some-image-4")
tabs.viewControllers = [nav1, nav2, nav3, nav4]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM