当前位置:   article > 正文

自定义UITabBarController Swift_自定义 uitabbarcontroller swift

自定义 uitabbarcontroller swift
  1. import UIKit
  2. class TabBarViewController: UITabBarController {
  3. override func viewDidLoad() {
  4. super.viewDidLoad()
  5. self.tabBar.backgroundColor = UIColor.white
  6. self.tabBar.isOpaque = false
  7. setUpTabBar(img: "首页", selImg: "首页Sel", title: "预警", viewController: MainViewController())
  8. setUpTabBar(img: "我的", selImg: "我的Sel", title: "我的", viewController: MineViewController())
  9. }
  10. func setUpTabBar(img:String, selImg:String, title:String, viewController:BasicViewController) {
  11. let nav = UINavigationController(rootViewController: viewController)
  12. nav.isNavigationBarHidden = true
  13. nav.tabBarItem.image = UIImage(named: img)?.withRenderingMode(.alwaysOriginal)
  14. nav.tabBarItem.selectedImage = UIImage(named: selImg)?.withRenderingMode(.alwaysOriginal)
  15. nav.title = title
  16. nav.tabBarItem.setTitleTextAttributes([.foregroundColor: UIColor(red: 165.0/255.0, green: 165.0/255.0, blue: 165.0/255.0, alpha: 1), .font: UIFont.systemFont(ofSize: 12)], for: UIControlState.normal)
  17. nav.tabBarItem.setTitleTextAttributes([.foregroundColor: ButtonColor, .font: UIFont.systemFont(ofSize: 12)], for: UIControlState.selected)
  18. self.addChildViewController(nav)
  19. }
  20. }

使用:

  1. let appDelegate = (UIApplication.shared.delegate) as! AppDelegate
  2. appDelegate.window!.rootViewController = TabBarViewController()

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/124891
推荐阅读
相关标签
  

闽ICP备14008679号