![](/img/trans.png)
[英]Change the text of UINavigationController not working in Swift
[英]swift - UINavigationController extension not working
我将在不同的视图控制器中的所有导航控制器上使用类似的属性,除了一些导航项和显然标题。
我做了一个扩展计划,可以调用它并设置我的默认值; 但是,它没有做任何事情。 当我只是将它放在实际的类中而不是在我调用SetDefaults时,代码确实有效。
扩展 :
extension UINavigationController {
func setDefaults(titleText: String){
let appDel = UIApplication.sharedApplication().delegate as! AppDelegate
//Set title label
let label = UILabel()
label.font = UIFont(name: appDel.regularDefaultFont, size: 16)
label.text = titleText
label.kern(1.0)
label.sizeToFit()
self.navigationItem.titleView = label
//Set white background tint color
self.navigationBar.barTintColor = UIColor.whiteColor()
//Set navigation bar bottom line
let bottomBorderRect = CGRect(x: 0, y: UIScreen.mainScreen().bounds.height, width: UIScreen.mainScreen().bounds.width, height: 1)
let bottomBorderView = UIView(frame: bottomBorderRect)
bottomBorderView.backgroundColor = UIColor(r: 250, g: 250, b: 250)
self.navigationBar.addSubview(bottomBorderView)
}
}
使用navigationcontroller从类调用SetDefaults:
self.navigationController.SetDefaults("Login")
你的代码应该是这样的。
let vcLogin = loginViewController(
nibName: "loginViewController",
bundle: nil)
navigationController?.pushViewController(vcLogin,
animated: true )
希望这就像水流一样......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.