美文网首页
7.1、初识UITabbar

7.1、初识UITabbar

作者: 艾希_可可 | 来源:发表于2018-06-27 11:43 被阅读2次

    import UIKit

    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    

    // App底部的tab标签页可以方便的把功能模块划分清楚,只需点击相应的标签页就可以展示完全独立的视图页面,同时各标签页间的视图也可以进行数据交换
    let tabbarVC = UITabBarController()
    self.window?.rootViewController = tabbarVC
    self.window?.makeKeyAndVisible()

        let one = UIViewController()
        one.view.backgroundColor = UIColor.cyan
        one.tabBarItem.title = "首页"
        one.tabBarItem.tag = 100
        one.tabBarItem.image = UIImage(named: "tabbar01_normal")
        one.tabBarItem.selectedImage = UIImage(named: "tabbar01_selected")?.withRenderingMode(.alwaysOriginal)
        
        let two = UIViewController()
        two.view.backgroundColor = UIColor.red
        two.tabBarItem.title = "我的"
        two.tabBarItem.tag = 101
        two.tabBarItem.image = UIImage(named: "tabbar02_normal")
        two.tabBarItem.selectedImage = UIImage(named: "tabbar02_selected")?.withRenderingMode(.alwaysOriginal)
        
        tabbarVC.viewControllers = [one,two]
        tabbarVC.tabBar.isTranslucent = false
        tabbarVC.tabBar.tintColor = UIColor.yellow
        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 invalidate graphics rendering callbacks. Games should 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 active state; here you can undo many 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 previously 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:.
    }
    

    }

    相关文章

      网友评论

          本文标题:7.1、初识UITabbar

          本文链接:https://www.haomeiwen.com/subject/ogdbyftx.html