2015-03-03 73 views
1
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我找不到任何。Swift:如何將圖標圖像和圖像背景添加到App委託中的UItabBar?

預先感謝您。

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

謝謝你提前。

回答

2

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] 
+0

謝謝加文Bunney。 – 2015-03-03 14:26:19