美文网首页
Swift 中定义UITabBarController

Swift 中定义UITabBarController

作者: T_label | 来源:发表于2016-08-01 11:42 被阅读134次
  • UITabBarViewController.swift
    import UIKit
    class UITabBarViewController: UITabBarController {
    class func UITabBarViewController() ->UITabBarController{
    let vc1 = FirstViewController()
    let vc2 = SecondViewController()
    let vc3 = ThirdViewController()
    let vc4 = FourthController()
    let nvc1:UINavigationController = nav(rootViewController: vc1)
    let nvc2:UINavigationController = nav(rootViewController: vc2)
    let nvc3:UINavigationController = nav(rootViewController: vc3)
    let nvc4:UINavigationController = nav(rootViewController: vc4)
    let tabbar1 = UITabBarItem(title: "标题0", image: (Public .getImgView("nenu_first_off")) , selectedImage: (Public .getImgView("nenu_first_on")))
    let tabbar2 = UITabBarItem(title: "标题1", image: (Public .getImgView("nenu_second_off")), selectedImage: (Public .getImgView("nenu_second_on")))
    let tabbar3 = UITabBarItem(title: "标题2", image: (Public .getImgView("nenu_third_off")), selectedImage: (Public .getImgView("nenu_third_on")))
    let tabbar4 = UITabBarItem(title: "标题3", image: (Public .getImgView("nenu_fourth_off")), selectedImage: (Public .getImgView("nenu_service_on")))
    nvc1.tabBarItem = tabbar1
    nvc2.tabBarItem = tabbar2
    nvc3.tabBarItem = tabbar3
    nvc4.tabBarItem = tabbar4
    let tc = UITabBarController()
    tc.tabBar.tintColor = UIColor.init(colorLiteralRed:128.0/255.0, green:179.0/255.0, blue:255.0/255.0, alpha:1)
    tc.viewControllers = [nvc1,nvc2,nvc3,nvc4]
    return tc;
    }
    }

  • nav.swift
    import UIKit
    class nav: UINavigationController {
    override func viewDidLoad() {
    super.viewDidLoad()
    let navigationTitleAttribute : NSDictionary = NSDictionary(object: UIColor.whiteColor(),forKey: NSForegroundColorAttributeName)
    self.navigationBar.titleTextAttributes = navigationTitleAttribute as [NSObject : AnyObject] as? [String : AnyObject]
    self.navigationBar .setBackgroundImage(UIImage(named: "4.png"), forBarMetrics: .Default)
    }
    }

  • Public.swift
    import UIKit
    class Public: NSObject {
    class func getImgView(ImgName: NSString)->UIImage{
    var image:UIImage = UIImage(named: ImgName as String)!
    image = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    return image
    }
    }

相关文章

网友评论

      本文标题:Swift 中定义UITabBarController

      本文链接:https://www.haomeiwen.com/subject/nsmxsttx.html