Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active March 20, 2017 00:56
Show Gist options
  • Save KentarouKanno/9b8f44661524026590aa to your computer and use it in GitHub Desktop.
Save KentarouKanno/9b8f44661524026590aa to your computer and use it in GitHub Desktop.
UITabBarController

★ 指定したタブを選択状態にする

// 自分の持っているViewControllers(ViewControllerの配列)の1番目を選択する。
self.selectedViewController = self.viewControllers![1]

★ TabBarItemにバッジを付ける

self.tabBarItem.badgeValue = "123"

// TabbarControllerをRootViewから取得する場合は以下
let tabView = UIApplication.sharedApplication().keyWindow?.rootViewController as! UITabBarController
let rootView = tabView.viewControllers![0] as! ViewController
rootView.tabBarItem.badgeValue = "123"

★ 各画面でタブバーの表示非表示を切り替える

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    // タブバーを非表示にする
    self.tabBarController?.tabBar.isHidden = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment