IOS Swift3.1 手工代码编写主视图

1. 普通页面控制器

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = ViewController()
        window?.backgroundColor = UIColor.white
        window?.makeKeyAndVisible()

        return true
    }


2.  使用导航控制器

    var NavCtr : UINavigationController?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        window = UIWindow(frame: UIScreen.main.bounds)
NavCtr = UINavigationController(rootViewController: ViewController() )
        NavCtr?.setNavigationBarHidden(true, animated: false)//隐藏导航条,看起来像普通控制器
        window?.rootViewController = NavCtr
        window?.backgroundColor = UIColor.white
        window?.makeKeyAndVisible()
        
        return true
    }


3. 使用Tab页

    var window: UIWindow?
    var TabBar: UITabBarController?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.backgroundColor = UIColor.white
        window?.makeKeyAndVisible()
        
        TabBar = UITabBarController()
        
        window?.rootViewController = TabBar
        
        let v1 = VC1()
        let v2 = VC2()
        let v3 = VC3()
        let v4 = VC4()
        
        v1.tabBarItem.title = "t1"
        v2.tabBarItem.title = "t2"
        v3.tabBarItem.title = "t3"
        v4.tabBarItem.title = "t4"
        
        
        TabBar?.addChildViewController(v1)
        TabBar?.addChildViewController(v2)
        TabBar?.addChildViewController(v3)
        TabBar?.addChildViewController(v4)
        
        TabBar?.tabBar.isHidden = true //隐藏tab按钮,看起来像是普通页面
        
       // TabBar?.selectedIndex = 1  //代码中切换页面的方式
 
        return true
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值