appdelegate.swift//Tabbarcontrollerimport Uikit@uiapplicationmainclass Appdelegate:uiresponder, Uiapplicationdelegate {var window:uiwindow? Func application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [Nsobject:anyobject]?)- > Bool {//Override point for customization after application launch. self.window!. BackgroundColor = Uicolor. Whitecolor (); Create a 3//Create first interface Let Vc1:uiviewcontroller = Firstviewcontroller (); Let Nav1 = Uinavigationcontroller (ROOTVIEWCONTROLLER:VC1); Let Image1 = UIImage (named: "Sharepanel_ic_hvr_qq"); Nav1.tabbaritem = Uitabbaritem (title: "Session", Image:image1, tag:1); Let Vc2:uiviewcontroller = Scondviewcontroller (); Let nav2 = Uinavigationcontroller (ROOTVIEWCONTROLLER:VC2); Let Image2 = UIImage (named: "Sharepanel_ic_hvr_weibo"); Nav2.tabbaritem = Uitabbaritem (title: "SMS", Image:image2, Tag:2); Let Vc3:uiviewcontroller = Thirdviewcontroller (); Let nav3 = Uinavigationcontroller (ROOTVIEWCONTROLLER:VC3); Let Image3 = UIImage (named: "Sharepanel_ic_hvr_weixin"); Nav3.tabbaritem = Uitabbaritem (title: "Settings", Image:image3, Tag:3); Let arr = [nav1,nav2,nav3]; Let Tabbarcontroller = Uitabbarcontroller (); Tabbarcontroller.viewcontrollers = arr; self.window!. Rootviewcontroller = Tabbarcontroller; self.window!. Makekeyandvisible () return True} func applicationwillresignactive (application:uiapplication) {//Se NT when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frameRates. Games should use this method to pause the game. } func Applicationdidenterbackground (application:uiapplication) {//Use this method to release shared resource s, save user data, invalidate timers, and store enough application state information to restore your application to its CU Rrent state in case it is terminated later. If your application supports background execution, this method is called instead of Applicationwillterminate:when the User quits. } func Applicationwillenterforeground (application:uiapplication) {//called as part of the transition from the Background to the inactive state; Here's can undo many of the changes made on entering the background. } func applicationdidbecomeactive (application:uiapplication) {//Restart any tasks, were paused (or not ye T started) while the application was inactive. If the application is previously in the background, optionally refresh the user interface. } func appliCationwillterminate (application:uiapplication) {//Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:. }}
firstviewcontroller.swift// tabbarcontroller//import foundationimport uikitclass FirstViewController : Uiviewcontroller { override func Viewdidload () { super.viewdidload (); Self.view.backgroundColor = Uicolor. Purplecolor (); }}
scondviewcontroller.swift// tabbarcontrollerimport foundationimport uikitclass ScondViewController: Uiviewcontroller { override func Viewdidload () { super.viewdidload (); Self.view.backgroundColor = Uicolor. Orangecolor (); }}
thirdviewcontroller.swift// tabbarcontroller//import foundationimport uikitclass Thirdviewcontroller:uiviewcontroller { override func Viewdidload () { super.viewdidload (); Self.view.backgroundColor = Uicolor. Redcolor (); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swift-tabbar use, jump between pages