ios swift UITabBarController

来源:互联网 发布:js 点击添加class 编辑:程序博客网 时间:2024/06/10 16:43

        在AppDelegate中

        func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 方法内
   

       

 self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        self.window!.backgroundColor = UIColor.whiteColor()
        
        let vc1 = HomeViewController()
        let url1 = NSBundle.mainBundle().URLForResource("home", withExtension: "png")
        let nsData1 = NSData(contentsOfURL: url1!)
        let image1 = UIImage(data: nsData1!, scale: 5)//设置缩小五倍 可以用其他方式创建UIImage
        vc1.tabBarItem = UITabBarItem(title: "首页", image: image1, tag: 1)
       
        
        let vc2 = MakeMoneyViewController()
        let url2 = NSBundle.mainBundle().URLForResource("img2", withExtension: "png")
        let nsData2 = NSData(contentsOfURL: url2!)
        let image2 = UIImage(data: nsData2!, scale: 5)
        vc2.tabBarItem = UITabBarItem(title: "页面2", image: image2, tag: 2)
        
        let arr = [vc1, vc2]
        let tabBarController = UITabBarController()
        tabBarController.viewControllers = arr
        
        
        self.window!.rootViewController = tabBarController
        
        self.window!.makeKeyAndVisible()


0 0
原创粉丝点击