-
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
}
}
网友评论