我有一个 UINavigationBar
的子类。
如何在这个子类中设置 barTintColor
?
class NavBar: UINavigationBar {
override func sizeThatFits(_ size: CGSize) -> CGSize {
return CGSize(width:UIScreen.main.bounds.width, height: 66)
}
}
最佳答案
你只需要覆盖 UINavigationBar
的初始化程序。
class NavBar: UINavigationBar {
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
private func commonInit() {
// Change barTintColor to whatever you would like
self.barTintColor = .red
}
override func sizeThatFits(_ size: CGSize) -> CGSize {
return CGSize(width:UIScreen.main.bounds.width, height: 66)
}
}
关于ios - 如何从 UINavigationBar 子类设置 barTintColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43457744/