标签:
先上效果图如下:
1. 在APP 的AppDelegate页面中加载TFTabBarViewController类
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { self.window = UIWindow(frame:UIScreen.mainScreen().bounds) //let rootController = RootViewController(style: UITableViewStyle.Plain) let rootController = TFTabBarViewController() //TFLoginViewController() let rootNav = UINavigationController(rootViewController: rootController) self.window!.rootViewController = rootNav self.window!.backgroundColor = UIColor.whiteColor() self.window!.makeKeyAndVisible() return true }
3. 将刚刚创建的页面加载到TabBar中去
以下是源码:
import UIKit class TFTabBarViewController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() self.loadTabBarViewControllers() } func loadTabBarViewControllers(){ let firstVC = FirstViewController () let item1 : UITabBarItem = UITabBarItem (title: "首页", image: UIImage(named: "home_normal"), selectedImage: UIImage(named: "home_highlight")) firstVC.tabBarItem = item1 let secondVC = SecondViewController () let item2 : UITabBarItem = UITabBarItem (title: "购物", image: UIImage(named: "message_normal"), selectedImage: UIImage(named: "message_highlight")) secondVC.tabBarItem = item2 let thirdVC = ThirdViewController () let item3 : UITabBarItem = UITabBarItem (title: "旅游", image: UIImage(named: "mycity_normal"), selectedImage: UIImage(named: "mycity_highlight")) thirdVC.tabBarItem = item3 let fourthVC = FourthViewController () let item4 : UITabBarItem = UITabBarItem (title: "旅游", image: UIImage(named: "account_normal"), selectedImage: UIImage(named: "account_highlight")) fourthVC.tabBarItem = item4 let tabArray = [firstVC ,secondVC ,thirdVC, fourthVC] self.viewControllers = tabArray } }
标签:
原文地址:http://blog.csdn.net/robinson_911/article/details/51339142