【发布时间】:2016-05-04 20:26:45
【问题描述】:
我正在尝试创建一个应用程序,其中 UINavigationBar 和 UIView 的背景颜色相同。
这就是我所做的:
- 已创建 customUINavigationBar(继承自 UINavigationBar)
- 创建 customUIView(继承自 UIView)
然后我将以下代码添加到customUINavigationBar:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.backgroundColor = Colors.turquoise
let attributes = [NSFontAttributeName: UIFont(name: "AppleGothic", size: 20)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
self.titleTextAttributes = attributes
for parent in self.subviews {
for child in parent.subviews {
if child is UIImageView {
child.removeFromSuperview()
}
}
}
}
我还尝试将 self.barTintColor = Colors.turquoise 和 self.tintColor = Colors.turquoise 添加到 init 函数中,但这不会改变结果。
在我的customUIView 课程中,我有以下代码:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.backgroundColor = Colors.turquoise
}
Colors.turquoise 来自一个包含这行代码的自定义类:
static var turquoise = UIColor(red: 132/255, green: 217/255, blue: 217/255, alpha: 1.0)
以上代码的结果如截图所示。如您所见,导航栏和视图之间的颜色略有不同。如何在导航栏和视图中获得相同的颜色而不会有任何差异?
提前致谢!
【问题讨论】:
-
你试过 self.translucent = false; self.opaque = true 在您所需的 init?(coder aDecoder: NSCoder) 方法中?
-
刚刚尝试过,根据您的建议(也将半透明更改为真)会提供更暗的导航栏
标签: ios swift uiview uinavigationbar