简体   繁体   English

阴影图像在第一个视图上不起作用

[英]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.

相关问题 在iOS 6中, - [UITextField becomeFirstResponder]在-viewWillAppear中不起作用: - In iOS 6, -[UITextField becomeFirstResponder] doesn't work in -viewWillAppear: 在viewWillAppear中使用setNavigationBarHidden不起作用 - Using setNavigationBarHidden in viewWillAppear doesn't work 在viewWillAppear中调用performFetch不起作用 - Calling performFetch in viewWillAppear doesn't work 为什么从viewWillAppear或viewDidAppear中显示和隐藏视图不起作用 - Why showing and hiding view from viewWillAppear or viewDidAppear doesn't work 重置tabBar.isHidden在viewWillAppear中不起作用 - Reset tabBar.isHidden doesn't work in viewWillAppear CABasicAnimation未在viewWillAppear中触发 - CABasicAnimation doesn't trigger in viewWillAppear removeFromSuperview在视图中将不起作用 - removeFromSuperview does't work in the viewwillappear 带有遮罩的Shadow不适用于UIViewLayer - Shadow doesn't work with UIViewLayer with a mask collectionView 不会在 viewDidLoad 中重新加载数据,但它可以在 viewWillAppear 中工作 - collectionView doesn't reloadData in viewDidLoad but it works in viewWillAppear 关闭dismissViewController不会触发viewWillAppear - Closing dismissViewController doesn't fire the viewWillAppear
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM