将导航栏设置回默认值

时间:2015-03-27 11:35:47

标签: objective-c swift

我已经更改了视图的几个navigationBar属性。但是,我想确保在取消视图或显示新视图后,所有内容都会恢复为默认值。有没有办法重置所有值?

更改值:

    // set status bar white
    self.navigationController?.navigationBar.barStyle = UIBarStyle.Default

    // make navigation bar clear/transparent
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.translucent = false
    let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    self.navigationController?.navigationBar.titleTextAttributes = titleDict

1 个答案:

答案 0 :(得分:0)

如果有其他人需要这个:

func setNavigationBarDefaults() {
    self.navigationController?.navigationBar.barStyle = UIBarStyle.Default
    self.navigationController?.navigationBar.translucent = false
}

override func viewWillDisappear(animated: Bool) {
    setNavigationBarDefaults()
}