Swift-uinavigationcontroller Pure Code Custom navigation Controller and the use of the bottom toolbar

Source: Internet
Author: User
Tags uikit

Step1: Customizes a class Ntviewcontroller, which inherits Uitabbarcontroller:

////Ntviewcontroller.swift//Housekeeper////Created by Lu Yang on 15/10/20.//copyright©2015 year Niven Moore. All rights reserved.//Import Foundationimport UIKitclassntviewcontroller:uitabbarcontroller{var items=[]; //Page Initialization    Overridefunc viewdidload () {super.viewdidload (); //1. Create a home navigation controllerLet vwindex=index (); Let Navindex=Uinavigationcontroller (Rootviewcontroller:vwindex); Navindex.title="Home Page";
     //Set the image that the toolbar displays by default navIndex.tabBarItem.image=uiimage (named:"Home")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal);
     //Set the picture NavIndex.tabBarItem.selectedImage after the toolbar is selected =uiimage (named:"Homes.png")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); //2. Create an active information navigation controllerLet vwactivityinfo=Activityinfo (); Let Navactivityinfo=Uinavigationcontroller (Rootviewcontroller:vwactivityinfo); Navactivityinfo.title="Event Information"; NavActivityInfo.tabBarItem.image=uiimage (named:"Activity-information.png")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); NavActivityInfo.tabBarItem.selectedImage=uiimage (named:"Activity-informations.png")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); //3. Create a vehicle display navigation controllerLet vwcardisplay=Cardisplay (); Let Navcardisplay=Uinavigationcontroller (Rootviewcontroller:vwcardisplay); Navcardisplay.title="Vehicle Display"; NavCarDisplay.tabBarItem.image=uiimage (named:"Vehicle-display.png")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); NavCarDisplay.tabBarItem.selectedImage=uiimage (named:"Vehicle-displays.png")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); //4. Create a personal hub navigation controllerLet vwpersonalcenter=Personalcenter (); Let Navpersonalcenter=Uinavigationcontroller (Rootviewcontroller:vwpersonalcenter); Navpersonalcenter.title="Personal Center"; NavPersonalCenter.tabBarItem.image=uiimage (named:"Personal-center.png")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); NavPersonalCenter.tabBarItem.selectedImage=uiimage (named:"Personal-centers.png")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); //5. Add to Toolbaritems=[Navindex,navactivityinfo,navcardisplay,navpersonalcenter]; Self.viewcontrollers=items as?[Uiviewcontroller]; Self.navigationcontroller?. Navigationbar.tintcolor=Uicolor.whitecolor (); //6. Customizing toolbarsSelf.tabbar.backgroundcolor=Uicolor.clearcolor (); //Bottom Toolbar background colorSelf.tabbar.bartintcolor=Uicolor.appmaincolor (); //7. Set the bottom toolbar text color (default state and selected state)Uitabbaritem.appearance (). Settitletextattributes (Nsdictionary (Object: Uicolor.whitecolor (), Forkey:nsforegroundcolorattributename) as?[String:anyobject], forState:UIControlState.Normal); Uitabbaritem.appearance (). Settitletextattributes (Nsdictionary (Object: Uicolor.bluewithtabbar (), Forkey:nsforegroundcolorattributename) as?[String:anyobject], forState:UIControlState.Selected) }}

Step2: Open Appdelegate.swift

////Appdelegate.swift//Housekeeper////Created by Lu Yang on 15/10/14.//copyright©2015 year Niven Moore. All rights reserved.//Import Foundationimport Uikit@uiapplicationmainclassAppdelegate:uiresponder, uiapplicationdelegate {var window:uiwindow?func Application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject:anyobject]< /c5>?) -Bool {//after the application starts//1. Declaring an empty viewSelf.window =UIWindow (Frame:UIScreen.mainScreen (). bounds); Self.window!. Backgroundcolor=Uicolor.whitecolor (); //2.1 Navigating the background colorUinavigationbar.appearance (). bartintcolor=Uicolor.appmaincolor (); Uibarbuttonitem.appearance (). Setbackbuttontitlepositionadjustment (Uioffsetmake (CGFloat (NSInteger.min), CGFloat (        nsinteger.min)), ForBarMetrics:UIBarMetrics.Default); //2.2 Navigation title text colorUinavigationbar.appearance (). Titletextattributes=nsdictionary (Object: Uicolor.whitecolor (), Forkey:nsforegroundcolorattributename) as?[String:anyobject];
     //Landlord status bar color changed, set to white, if necessary, open Info.plist add key (View controller-based status bar appearance,value for no //2.3 Change the status bar to whiteUiapplication.sharedapplication (). Statusbarstyle =uistatusbarstyle.lightcontent; //2.4 Set Back button colorUinavigationbar.appearance (). tintcolor=Uicolor.whitecolor (); //3. Specify the root viewLet rootview=Ntviewcontroller (); Self.window!. Rootviewcontroller=Rootview; Self.window!. makekeyandvisible (); return true} func applicationwillresignactive (application:uiapplication) {//Sent 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 the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.} func Applicationdidenterbackground (application:uiapplication) {//Use the method to release the shared resources, save user data, invalidate timers, and store enough application state in Formation to the restore your application to the it is terminated later. //If Your application supports background execution, this method is called instead of Applicationwillterminate:when th E user quits.} func Applicationwillenterforeground (application:uiapplication) {//Called as part of the transition from the background to the inactive state; Here you can undo many of the changes mad E on entering the background.} func applicationdidbecomeactive (application:uiapplication) {//Restart Any tasks this were paused (or not yet started) while the application is 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:. }}

As follows: The contents of the middle display is my project, you can ignore it, haha.

Swift-uinavigationcontroller Pure Code Custom navigation Controller and the use of the bottom toolbar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.