UITabBarController

9.png
//對象
let tarCtrl = UITabBarController()
//標(biāo)簽顏色
tarCtrl.tabBar.barTintColor = UIColor.blackColor() 
//字體
tarCtrl.tabBar.tintColor = UIColor.redColor()
//標(biāo)簽控制器里面裝的成員 它是以數(shù)組的形式

//把導(dǎo)航控制器加在標(biāo)簽控制器里面
let first = firstViewController()
 let navCtrl = UINavigationController(rootViewController: first)
navCtrl.tabBarItem.image = UIImage(named: "78")?.imageWithRenderingMode(.AlwaysOriginal)

 let second = secondViewController()
 second.tabBarItem.title = "second"
 second.tabBarItem.badgeValue = "10"

let third = thirdViewController()
third.tabBarItem.title = "third"
tarCtrl.viewControllers = [navCtrl,second,third]
self.window?.rootViewController = tarCtrl

協(xié)議UITabBarControllerDelegate

tarCtrl.delegate = self //代理

代理實現(xiàn)

//第二個參數(shù)為將要選中的頁面
//只能阻止通過點擊標(biāo)簽欄跳轉(zhuǎn),不能阻止通過代碼改變selectedIndex跳轉(zhuǎn)
    func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
        let index = tabBarController.viewControllers?.indexOf(viewController)
      //當(dāng)選擇第二個時,就彈出一個新的界面
        if index == 1{
            let four = fourViewController()
            tabBarController.presentViewController(four, animated: true, completion: nil)
            return false //隱藏第二頁 直接顯示four
        }
     return true
    }

當(dāng)觸發(fā)第一個界面,就直接跳轉(zhuǎn)到第二個界面

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
 self.tabBarController?.selectedIndex = 1
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容