码迷,mamicode.com
首页 > 编程语言 > 详细

swift TabBar

时间:2016-05-13 04:36:53      阅读:361      评论:0      收藏:0      [点我收藏+]

标签:

先上效果图如下:

技术分享

1. 在APP 的AppDelegate页面中加载TFTabBarViewController类

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
        
        //let rootController = RootViewController(style: UITableViewStyle.Plain)
        let rootController = TFTabBarViewController()  //TFLoginViewController()
        let rootNav = UINavigationController(rootViewController: rootController)
        self.window!.rootViewController = rootNav
        self.window!.backgroundColor = UIColor.whiteColor()
        self.window!.makeKeyAndVisible()
        
        return true
    }

2. 创建 FirstViewController ,SecondViewController,ThirdViewController,FourthViewController四个页面,然后设置下页面的颜色(便于点击下面的TabBar时,可以看到切换的效果)

3. 将刚刚创建的页面加载到TabBar中去

以下是源码:

import UIKit

class TFTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.loadTabBarViewControllers()
    }

    func loadTabBarViewControllers(){
        let firstVC  = FirstViewController ()
        let item1 : UITabBarItem = UITabBarItem (title: "首页", image: UIImage(named: "home_normal"), selectedImage: UIImage(named: "home_highlight"))
        firstVC.tabBarItem = item1
        
        let secondVC = SecondViewController ()
        let item2 : UITabBarItem = UITabBarItem (title: "购物", image: UIImage(named: "message_normal"), selectedImage: UIImage(named: "message_highlight"))
        secondVC.tabBarItem = item2
        
        let thirdVC = ThirdViewController ()
        let item3 : UITabBarItem = UITabBarItem (title: "旅游", image: UIImage(named: "mycity_normal"), selectedImage: UIImage(named: "mycity_highlight"))
        thirdVC.tabBarItem = item3
        
        let fourthVC = FourthViewController ()
        let item4 : UITabBarItem = UITabBarItem (title: "旅游", image: UIImage(named: "account_normal"), selectedImage: UIImage(named: "account_highlight"))
        fourthVC.tabBarItem = item4
        
        let tabArray = [firstVC ,secondVC ,thirdVC, fourthVC]
        self.viewControllers = tabArray
    }
}


swift TabBar

标签:

原文地址:http://blog.csdn.net/robinson_911/article/details/51339142

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!