The custom _swift of Swift's Uitabbarcontroller navigation controller

Source: Internet
Author: User
Tags reserved uikit

Swift navigation controller, navigation controller class inherits Uitabbarcontroller, as shown in the following code:

 Appdelegate.swift//housekeeper////Created by Lu Yang on//. Copyright© years Niven Moore.
 All rights reserved. Import Foundation Import Uikit @UIApplicationMain class Appdelegate:uiresponder, uiapplicationdelegate {var wi
   Ndow:uiwindow?
   var indextab:uitabbarcontroller?; Func application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [Nsobject:anyobject]?)-
     > Bool {//Application startup//. Declares an empty view Self.window = UIWindow (Frame:UIScreen.mainScreen (). bounds); self.window!.
     Backgroundcolor=uicolor.whitecolor ();
     . Navigation background color uinavigationbar.appearance (). Bartintcolor=uicolor.appmaincolor (); Uibarbuttonitem.appearance (). Setbackbuttontitlepositionadjustment (Uioffsetmake (CGFloat (NSInteger.min), CGFloat (
     nsinteger.min)), ForBarMetrics:UIBarMetrics.Default); . Navigation title text color Uinavigationbar.appearance (). Titletextattributes=nsdictionary (Object:UIColor.whiteColor (), Forkey: Nsforegroundcolorattributename) as? [String:anyoBject];
     . Change the status bar to White Uiapplication.sharedapplication (). Statusbarstyle = Uistatusbarstyle.lightcontent;
    . Set the return button Color Uinavigationbar.appearance (). Tintcolor=uicolor.whitecolor ();
     . Specifies the root view let Rootview=ntviewcontroller (); self.window!.
     Rootviewcontroller=rootview; self.window!.
     Makekeyandvisible ();
     . Initialize Keyboard plugin//let manage:iqkeyboardmanager=iqkeyboardmanager.sharedmanager ();
     Manage.enable=true;
     Manage.shouldresignontouchoutside=true;
     Manage.shouldtoolbarusestextfieldtintcolor=true;
     Manage.enableautotoolbar=true; return true} func applicationwillresignactive (application:uiapplication) {//Sent then the application is AB Out 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 the US
     Er quits the application and it begins the transition to the background state. Use the To pause ongoing TAsks, disable timers, and throttle down OpenGL ES frame rates.
   Games should to pause the game.  } func Applicationdidenterbackground (application:uiapplication) {//Use the Save user data, invalidate timers, and store enough application state information to restore your application to its Curr
     ENT State in case it is terminated later. If your application supports background execution, this is called instead of Applicationwillterminate:when the
   User quits. } func Applicationwillenterforeground (application:uiapplication) {//called as part of the transition from the B Ackground to the inactive state;
   Here you can undo many of the changes made 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 was about to terminate . Save data if appropriate.
   Also applicationdidenterbackground:.

 }
 }

2. The following is my custom navigation controller class, inheriting Uitabbarcontroller

Ntviewcontroller.swift//housekeeper////Created by Lu Yang on//. Copyright© years Niven Moore.
 All rights reserved. Import Foundation Import Uikit class ntviewcontroller:uitabbarcontroller{//page initialization override func Viewdidload ()
     {super.viewdidload ();
     . Create home navigation Controller let Vwindex=index ();
     Let Navindex=uinavigationcontroller (Rootviewcontroller:vwindex);
     Navindex.title= "Home"; Navindex.tabbaritem.image=uiimage (named: "Home.png")? Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); Default display Picture Navindex.tabbaritem.selectedimage=uiimage (named: "Homes.png")? Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal);
     Selected Pictures//. Create an active information navigation controller let Vwactivityinfo=activityinfo ();
     Let Navactivityinfo=uinavigationcontroller (Rootviewcontroller:vwactivityinfo);
     navactivityinfo.title= "Activity information"; Navactivityinfo.tabbaritem.image=uiimage (named: "Activity-information.png")? Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); Navactivityinfo.tabbaritem.selectedimage=uiimage (named: "Activity-informations.png")?
     Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal);
     . Create vehicle display navigation Controller let 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);
     Create a personal center navigation controller Let Vwpersonalcenter=personalcenter ();
     Let Navpersonalcenter=uinavigationcontroller (Rootviewcontroller:vwpersonalcenter);
     navpersonalcenter.title= "Personal centre"; Navpersonalcenter.tabbaritem.image=uiimage (named: "Personal-center.png")?
     Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal); Navpersonalcenter.tabbaritem.selectedimage=uiimage (named: "Personal-centers.png ")?
     Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal);
     . Add to toolbar let Items=[navindex,navactivityinfo,navcardisplay,navpersonalcenter];
     Self.viewcontrollers=items; Self.navigationcontroller?
     Navigationbar.tintcolor=uicolor.whitecolor ();
     . Customize the toolbar self.tabbar.backgroundcolor=uicolor.clearcolor ();
     Bottom toolbar background color self.tabbar.bartintcolor=uicolor.appmaincolor (); . Sets the bottom toolbar text color (default state and checked 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)//self.tabbar.tintcolordidchange () =uicolor.greencolor ();
 Let Viewbar=uiview (Frame:cgrectmake (,, Uiscreen.mainscreen (). bounds.width)); //Viewbar.backgroundcolor=uicolor (Patternimage:uiimage (named: "Tabbarbg.png")!); Self.tabBar.insertSubview (ViewBar, Atindex:)//self.tabbar.opaque=true//Self.tabbar.tintcolor=uicolor.app
   Maincolor (); }
 }

The effect chart is as follows:

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.