[英]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.