要在故事板做好这项工作(界面Builder Inspector)
在IBDesignable
的帮助下,我们可以在Interface Builder Inspector中为UINavigationController
添加更多选项,并在故事板上调整它们。首先,将以下代码添加到您的项目中。
@IBDesignable extension UINavigationController {
@IBInspectable var barTintColor: UIColor? {
set {
navigationBar.barTintColor = newValue
}
get {
guard let color = navigationBar.barTintColor else { return nil }
return color
}
}
@IBInspectable var tintColor: UIColor? {
set {
navigationBar.tintColor = newValue
}
get {
guard let color = navigationBar.tintColor else { return nil }
return color
}
}
@IBInspectable var titleColor: UIColor? {
set {
guard let color = newValue else { return }
navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: color]
}
get {
return navigationBar.titleTextAttributes?["NSForegroundColorAttributeName"] as? UIColor
}
}
}
然后只需在故事板上设置UINavigationController的属性即可。
谢谢!它工作很好。 – Raja 2017-08-21 09:52:06