我正在尝试更改导航栏的颜色,但我发现如果导航器是根导的话,这是不可能的.
我正在尝试这个:
self.navigationController?.navigationBar.translucent = true self.navigationController!.navigationBar.barTintColor = UIColor.blueColor()
我的所有Viewcontrollers都与导航控制器有关.然而,没有任何改变.事实上,我试图从故事板中制作相同的东西,但只有当我在第一个导航器中时才有效.
我试图阅读与此问题相关的所有内容,但一无所获
我可以像这样添加任何项目到导航栏
let HomeImage = UIImage(named: "home")! let Home : UIBarButtonItem = UIBarButtonItem(image: HomeImage,style: .Plain,target: self,action: "home:") navigationItem.rightBarButtonItem = Home
事实上,我发现解决方案是在AppDelegate.siwft中使用:
原文链接:https://www.f2er.com/swift/320262.htmlfunc application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. UINavigationBar.appearance().barTintColor = UIColor(red: 0,green: 0/255,blue: 205/255,alpha: 1) UINavigationBar.appearance().tintColor = UIColor.whiteColor() UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()] return true }
然后在每个视图控制器中,我们需要另一种背景颜色或其他东西
> segue应该与“show”不同
>使用func viewWillAppear
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor() self.navigationController?.navigationBar.tintColor = UIColor.blueColor() self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blueColor()] }