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

相關文章
相關標籤/搜索