我的代码遇到以下问题:
在我的应用程序上,我有一个导航 Controller ,并且我根据我使用此功能呈现的 View Controller 来设置栏的样式:
func styleNavBar(barColor: String){
let logo = UIImage(named: "logo-sura.pdf")
let imageView = UIImageView(image:logo)
self.navigationItem.titleView = imageView
switch barColor {
case "Dark":
self.navigationController?.navigationBar.barTintColor = UIColor.blackColor()
return
case "Light":
self.navigationController?.navigationBar.barTintColor = UIColor(netHex: 0x1CBBE1)
return
default:
return
}
}
它按照底部 View Controller 的预期工作(通过 segue 呈现)-我附加了图像-Story board that shows teh viewcontroller flow但在与 tabBar 关联的标签栏上,它不会显示 Logo 或导航项目。
任何关于我缺少什么的指针。
最佳答案
看到你的 Storyboard后,我建议执行以下操作:
实例化您的标签栏 Controller 并呈现它。
将每个选项卡栏 subview Controller 嵌入导航 Controller 中。正如 this answer 中所建议的
你的 Storyboard将如下所示:
显示标签栏 Controller :
@IBAction func buttonPressed(sender: AnyObject) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController
self.presentViewController(tabBarController,animated:true, completion:nil)
}
然后在你 child 的 vc 中
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let logo = UIImage(named: "logo")
let imageView = UIImageView(image:logo)
self.navigationItem.titleView = imageView
}
请告诉我它是否适合您。
关于iOS-swift 导航 Controller 样式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36992537/