IOS/Swift 学习之UITabBarContorller 14-10-14

UITabBarContorller
app


1、在appDelegate的入口函数编写当前视图
函数


添加多个UIViewContorller
学习

        //第一个tab
        let vc1 = ViewController()
        let chat = UINavigationController(rootViewController: vc1)
        chat.tabBarItem = UITabBarItem(title: "聊天", image: nil, tag: 1)
        
        //第二个tab
        let vc2 = ViewController()
        let friend = UINavigationController(rootViewController: vc2)
        friend.tabBarItem = UITabBarItem(title: "朋友", image: nil, tag: 2)
        
        //第三个tab
        
        let vc3 = ViewController()
        let me = UINavigationController(rootViewController: vc3)
        me.tabBarItem = UITabBarItem(title: "我", image: nil, tag: 3)


其中UITabBarItem中几个参数分别 title:显示的文字标题,image表示显示的图标,tag,应该是做为标记spa

UITabBarItem的几个构造函数,由第二个函数也能够看出能够设置选中的图片,因为如今只是刚刚学习,就先不实验图片的具体效果code

    init(title: String?, image: UIImage?, tag: Int)
    @availability(iOS, introduced=7.0)
    init(title: String?, image: UIImage?, selectedImage: UIImage?)
    init(tabBarSystemItem systemItem: UITabBarSystemItem, tag: Int)


2、添加UITabBarContorller图片


定义一个UITabBarContorller并把上面定义的三个UIViewContorller添加到里面,而后显示UITabVarContorllerit

        let tabBarContorller = UITabBarController()

        tabBarContorller.viewControllers = [chat, friend, me] //把UIViewContorller添加到UItabBarContorller中
        
        self.window?.rootViewController = tabBarContorller

这样,一个简单的UITabBarContorller就显示出来了io

相关文章
相关标签/搜索