swift 修改 Navigationbar Tabbar 字体颜色背景等属性

1.navigationBar的设置

let navColor = UIColor(red: 41/255, green: 160/255, blue: 230/255, alpha: 1)

func setNavibar() -> Void { self.navigationController?.navigationBar.barTintColor = navColor; self.navigationController?.navigationBar.tintColor = UIColor.white; self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white,NSAttributedStringKey.font:UIFont.boldSystemFont(ofSize:20)]; self.navigationItem.backBarButtonItem = UIBarButtonItem.init(title: "", style: .plain, target: nil, action: nil); }

 

2.tabbar 的设置

        self.tabBar.barTintColor=UIColor.gray;
        //.设置底部工具栏文字颜色(默认状态和选中状态)(选中状态为蓝色)
        UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object:UIColor.white, forKey:NSForegroundColorAttributeName as NSCopying) as? [String : AnyObject], for:UIControlState.normal);
        UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object:UIColor.blue, forKey:NSForegroundColorAttributeName as NSCopying) as? [String : AnyObject], for:UIControlState.selected)

 

tabbar 选中照片的颜色

    var image:UIImage = UIImage(named: imageName)!  
       var selectedimage:UIImage = UIImage(named: selectImageName)!;  
       image = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);  
       selectedimage = selectedimage.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);  
       vc.tabBarItem.image = image  
       vc.tabBarItem.selectedImage = selectedimage  

 

posted @ 2017-10-27 15:54  user_bo  阅读(813)  评论(0编辑  收藏  举报