ios swift UITabBarController

本文介绍如何在 iOS 应用程序中使用 Swift 语言初始化 UITabBarController,并为其中的两个视图控制器设置图标和标题。

        在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()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值