[英]Shadow Image doesn't work on the first viewWillAppear
I am trying to implement a seperatorline between the navigationbar and the content. 我正在尝试在导航栏和内容之间实现分隔线。 I found a UIImage extension, which creates an image with a color.
我找到了UIImage扩展,该扩展创建带有颜色的图像。
extension UIImage {
class func imageWithColor(color: UIColor) -> UIImage {
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 0.5)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
color.setFill()
UIRectFill(rect)
let image : UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
}
I put this in the viewWillAppear like that: 我这样将它放在viewWillAppear中:
navigationController?.navigationBar.shadowImage = UIImage.imageWithColor(color: constants.lightBlue)
This works well, if I click on an entry in my collection view and come back to the initial view controller. 如果我在集合视图中单击一个条目并返回到初始视图控制器,这将很好地工作。 However, it doesn't get loaded on the first startup of the app.
但是,它不会在应用程序的首次启动时加载。
Why don't you just create simple UIView with backgroundColor? 您为什么不只使用backgroundColor创建简单的UIView? You can place it by frame or constraint and it should work well.
您可以按框架或约束放置它,并且效果很好。
I mean, you can even create it in Storyboard and don't use code at all 我的意思是,您甚至可以在Storyboard中创建它,而根本不使用代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.