Development environment: Xcode 7 Beta 4
1.1: Deploy the Preliminary schema
1. 2 Setting the root controller (appdelegate.swift)
<span style= "Font-family:microsoft Yahei;" > func Application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [NSObject: Anyobject]?) -Bool { //Override point for customization after application launch. window = UIWindow (Frame:UIScreen.mainScreen (). Bounds) window?. BackgroundColor = Uicolor.whitecolor () window?. Rootviewcontroller = Mainuitabbarcontroller () window?. Makekeyandvisible () return True }</span>
1.3 Custom Tarbbar
<span style= "Font-family:microsoft Yahei;" >import uikitclass Mainuitabbarcontroller:uitabbarcontroller {override func Viewdidload () {Super.viewdidlo AD ()//Do any additional setup after loading the view. Addchildviewcontrollers () Setcomposebutton ()}//Set button private func Setcomposebutton () { Calculate the button height let w = tabbar.bounds.width/cgfloat (viewcontrollers!. count)//Button already has a width and height of rect let rect = CGRect (x:0, y:0, Width:w, Height:tabBar.bounds.height) Use offset to set button position Composebutton.frame = Cgrectoffset (Rect, 2 * w, 0)}///Add all child controllers Private Func addchildviewcontrollers () {//start adds all child controllers--------------------------Addchildview Controller (Hometableviewcontroller (), title: "Home", ImageName: "Tabbar_home") Addchildviewcontroller (Messageta Bleviewcontroller (), title: "Message", ImageName: "Tabbar_message_center") Addchildviewcontroller (Uiviewcontroller ()) Addchildviewcontroller (Discovertableviewcontroller (), TI TLE: "Discovery", ImageName: "Tabbar_discover") Addchildviewcontroller (Profiletableviewcontroller (), title: "I", image Name: "Tabbar_profile")//end-----------------------------------------}//Lazy load Create button lazy Private V Ar Composebutton:uibutton = {Let button = UIButton ()//start set button footage------------------ ---------------Button.setimage (UIImage (named: "Tabbar_compose_icon_add"), ForState:UIControlState.Normal) Button.setimage (UIImage (named: "tabbar_compose_icon_add_highlighted"), forState:UIControlState.Highlighted) Button.setbackgroundimage (UIImage (named: "Tabbar_compose_button"), ForState:UIControlState.Normal) Button.setbackgroundimage (UIImage (named: "tabbar_compose_button_highlighted"), Forstate: uicontrolstate.highlighted)//end-----------------------------------------------//Do not prompt for Self.tabBar.addSubview (button) button here. AddTarget (Self, Action: "Clickcomposebutton", ForControlEvents:UIControlEvents.TouchUpInside) return Butto n} ()///////////////-parameter VC: View Controller///parameter title: Title/// -parameter imageName: Image name private func Addchildviewcontroller (Vc:uiviewcontroller, title:string, imagename:string) {Tabbar.tintcolor = Uicolor.orangecolor () vc.title = Title Vc.tabBarItem.image = UIImage (Named:ima Gename) Let Nav = Uinavigationcontroller (ROOTVIEWCONTROLLER:VC) Addchildviewcontroller (NAV)} </span>
1.4 Setting up the login interface through an inheritance relationship
Note: Depending on whether the user is logged in to determine whether the interface switch
1.4.1 Customizing a controller that inherits Uitableviewcontroller
1.4.2 Modify the inheritance relationships of all controllers, inheriting Basetableviewcontroller
1.4.3 Setting the view of Basetableviewcontroller
<span style= "Font-family:microsoft Yahei;" >/ //Set Custom login View private func Setvistorview () { //Create empty view, test using view = UIView () //Set color View.backgroundcolor = Uicolor.orangecolor () }</span>
1.4.4 overriding Basetableviewcontroller's Loadview () method
<span style= "Font-family:microsoft Yahei;" >//defines whether a user is logged on with a switch var userlogin = true</span>
<span style= "Font-family:microsoft Yahei;" > override func Loadview () { //Determine if user login successfully switched view userlogin? Super.loadview (): Setvistorview () } </span>
12 consecutive days updates per day one stage
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Pure Code] Swift 2.0 develops Sina Weibo--the first day