美文网首页
7.3、系统导航控制器与分栏控制器结合

7.3、系统导航控制器与分栏控制器结合

作者: 艾希_可可 | 来源:发表于2018-06-27 11:47 被阅读8次
    import UIKit
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            // 视图1
            let vc01 = UIViewController()
            vc01.title = "视图1"
            vc01.view.backgroundColor = UIColor.green
            let nav01 = UINavigationController(rootViewController: vc01)
            // 视图2
            let vc02 = UIViewController()
            vc02.title = "视图2"
            vc02.view.backgroundColor = UIColor.yellow
            let nav02 = UINavigationController(rootViewController: vc02)
            // 视图3
            let vc03 = UIViewController()
            vc03.title = "视图3"
            vc03.view.backgroundColor = UIColor.orange
            let nav03 = UINavigationController(rootViewController: vc03)
            // 视图4
            let vc04 = UIViewController()
            vc04.title = "视图4"
            vc04.view.backgroundColor = UIColor.brown
            let nav04 = UINavigationController(rootViewController: vc04)
    
            let tabbarController = UITabBarController()
            self.window!.rootViewController = tabbarController
            self.window!.makeKeyAndVisible()
            tabbarController.viewControllers = [nav01, nav02, nav03, nav04]
            // 属性设置
    //        设置tabBar的背景色
            tabbarController.tabBar.barTintColor = UIColor.white
            // 设置默认被选中视图控制器
            tabbarController.selectedIndex = 0;
            // 设置切换视图 tabBar 属性
            // 1 打开用户交互
            tabbarController.tabBar.isUserInteractionEnabled = true;
            // 2 设置背景颜色
            tabbarController.tabBar.backgroundColor = UIColor.white
            // 3 设置背景图片
            tabbarController.tabBar.backgroundImage = UIImage(named: "")
            // 4 选中时的背景图片
            tabbarController.tabBar.selectionIndicatorImage = UIImage(named: "")
    
            //设置标题,未选中状态图标,选中状态图标
            let barItem01 = UITabBarItem(title: "第1视图", image: UIImage(named: "tabbar01_normal"), selectedImage: UIImage(named: "tabbar01_selected"))
            vc01.tabBarItem = barItem01
    
            let barItem02 = UITabBarItem(title: "第2视图", image: UIImage(named: "tabbar02_normal"), selectedImage: UIImage(named: "tabbar02_selected"))
            vc02.tabBarItem = barItem02
    
            let barItem03 = UITabBarItem(title: "第3视图", image: UIImage(named: "tabbar03_normal"), selectedImage: UIImage(named: "tabbar03_selected"))
            vc03.tabBarItem = barItem03
            let barItem04 = UITabBarItem(title: "第4视图", image: UIImage(named: "tabbar04_normal"), selectedImage: UIImage(named: "tabbar04_selected"))
            vc04.tabBarItem = barItem04
    ////显示图片的颜色
            let myItem = tabbarController.tabBar.items?[2]
            let myItemImg = UIImage(named: "tabbar03_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
            myItem?.selectedImage = myItemImg
            //设置字体颜色
            UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.white], for: .normal)
            UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.green], for: .selected)
            // 设置字体大小
            UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12.0)], for: UIControlState())
            // 设置字体偏移
            UITabBarItem.appearance().titlePositionAdjustment = UIOffsetMake(0.0, -5.0)
            // 设置图标选中时颜色
            UITabBar.appearance().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.3、系统导航控制器与分栏控制器结合

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