直接上代码
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "NavigationBar"), forBarMetrics: UIBarMetrics.Default)
let contrllers:Array = [ServiceHomeViewController(),ServiceNearViewController(),ServiceMyServeViewController(),ServiceMyMoneyViewController(),ServiceMyViewController(),]
var navVCArray:Array<UIViewController> = Array()
var images:Array! = ["Tabbar_home.png","Tabbar_Surrounding.png","Tabbar_shop.png","Tabbar_finance.png","Tabbar_mine.png"]
var selectImage:Array! = ["Tabbar_home_slect.png","Tabbar_Surrounding_slect.png","Tabbar_shop_slect.png","Tabbar_finance_slect.png","Tabbar_mine_slect.png"]
let titleArray = ["","附近","我的服务","我的财务","我"]
let ItemArray = ["首页","附近","我的服务","我的财务","我"]
for temp in 0...4{
let tabVC = contrllers[temp]
tabVC.navigationItem.title = titleArray[temp] //标题
tabVC.tabBarItem.title = ItemArray[temp] //item标题
tabVC.tabBarItem.image = UIImage(named:images[temp])!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)//未选中图片
tabVC.tabBarItem.selectedImage = UIImage(named:selectImage[temp])!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)//选中后图片
let nav:UINavigationController = UINavigationController(rootViewController: tabVC)
nav.navigationBar.titleTextAttributes = [NSFontAttributeName:UIFont.systemFontOfSize(NAVIGATIONBAR_TITLEFONT)]//设置标题颜色样式
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.HexString("d80000")], forState: UIControlState.Selected)
//选中后字体颜色 UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.HexString("959595")], forState: UIControlState.Normal)
navVCArray.append(nav)
//正常显示字体颜色
}
self.viewControllers = navVCArray