Swift-UINavigationController: use of the code-only custom navigation controller and the toolbar at the bottom, ledcontroller Controller

Source: Internet
Author: User

Swift-UINavigationController: use of the code-only custom navigation controller and the toolbar at the bottom, ledcontroller Controller

Step 1: Customize a class NTViewController, which inherits UITabBarController:

/// NTViewController. swift // Housekeeper /// Created by Lu Yang on 15/10/20. // Copyright©November 2015. all rights reserved. // import Foundationimport UIKitclass NTViewController: UITabBarController {var items = []; // The page initializes override func viewDidLoad () {super. viewDidLoad (); // 1. create the homepage navigation controller let vwIndex = index (); let navIndex = UINavigationController (rootViewController: vwIndex); navIndex. title = "Homepage ";
// Set the default image navIndex. tabBarItem. image = UIImage (named: "home ")?. ImageWithRenderingMode (UIImageRenderingMode. AlwaysOriginal );
// Set the image navIndex. tabBarItem. selectedImage = UIImage (named: "homes.png") after the toolbar is selected ")?. ImageWithRenderingMode (UIImageRenderingMode. alwaysOriginal); // 2. create an activity 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); // 3. create a 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); // 4. create a personal center navigation controller let 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 it to the toolbar items = [navIndex, navActivityInfo, navCarDisplay, navPersonalCenter]; self. viewControllers = items? [UIViewController]; self. navigationController ?. NavigationBar. tintColor = UIColor. whiteColor (); // 6. custom toolbar self. tabBar. backgroundColor = UIColor. clearColor (); // the background color self in the toolbar at the bottom. tabBar. barTintColor = UIColor. appMainColor (); // 7. set the text color (default status and selected status) in the bottom toolbar UITabBarItem. appearance (). setTitleTextAttributes (NSDictionary (object: UIColor. whiteColor (), forKey: NSForegroundColorAttributeName)? [String: AnyObject], forState: UIControlState. Normal); UITabBarItem. appearance (). setTitleTextAttributes (NSDictionary (object: UIColor. blueWithTabbar (), forKey: custom)? [String: AnyObject], forState: UIControlState. Selected )}}

Step 2: Open AppDelegate. swift

/// AppDelegate. swift // Housekeeper // Created by Lu Yang on 15/10/14. // Copyright©On February 16, 2015, nevenmoore. All rights reserved. // import Foundationimport UIKit @ UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow? Func application (application: UIApplication, didfinishlaunchingwitexceptions launchOptions: [NSObject: AnyObject]?) -> Bool {// After the application starts, // 1. Declare an empty view self. window = UIWindow (frame: UIScreen. mainScreen (). bounds); self. window !. BackgroundColor = UIColor. whiteColor (); // 2.1 Background Color UINavigationBar. appearance (). barTintColor = UIColor. appMainColor (); UIBarButtonItem. appearance (). setBackButtonTitlePositionAdjustment (UIOffsetMake (CGFloat (NSInteger. min), CGFloat (NSInteger. min), forBarMetrics: UIBarMetrics. default); // 2.2 navigation title text color UINavigationBar. appearance (). titleTextAttributes = NSDictionary (object: UIColor. whiteColor (), forKey: NSForegro UndColorAttributeName)? [String: AnyObject];
// The main poster's status bar has changed color and is set to white. If necessary, open info. add Key (View controller-based status bar appearance, Value is no // 2.3 to change the status bar to white UIApplication. sharedApplication (). statusBarStyle = UIStatusBarStyle. lightContent; // 2.4 set the return button color UINavigationBar. appearance (). tintColor = UIColor. whiteColor (); // 3. specify the Root View let rootView = NTViewController (); self. window !. RootViewController = rootView; self. window !. MakeKeyAndVisible (); return true} func applicationWillResignActive (application: UIApplication) {// Sent when the application is about to move from active to inactive state. this can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user 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 frame rates. games shocould use this method to pause the game .} func applicationDidEnterBackground (application: UIApplication) {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current 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 you can undo changes of the changes made on entering the background .} func applicationDidBecomeActive (application: UIApplication) {// Restart any tasks that were paused (or not yet started) while the application was inactive. if the application was previusly in the background, optionally refresh the user interface .} func applicationWillTerminate (application: UIApplication) {// Called when the application is about to terminate. save data if appropriate. see also applicationDidEnterBackground :.}}

The content shown in the middle is my project. You can ignore it, haha.

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.