swift - 模糊框架顶部和底部的 UiImageView

标签 swift iphone ios11 uiblureffect uib

Reference Image

我的 View Controller 上有一个图像,而在 ImageView 的顶部我有一些标签,但由于标签文本可见性,我需要模糊 UIImageView 忽略器的顶部和底部以清楚地显示文本。

我已附上我的设计忽略器的屏幕截图,以获得清晰的想法。

请引用图像以获得正确的输出。

最佳答案

将此代码添加到您的UIImageView中。

let gradientLayer = CAGradientLayer()
gradientLayer.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: self.imgView.frame.size.width, height: self.imgView.frame.size.height*0.3))
gradientLayer.colors = [UIColor.black.withAlphaComponent(0.7).cgColor, UIColor.clear.cgColor]
self.imgView.layer.addSublayer(gradientLayer)

let gradientLayer2 = CAGradientLayer()
gradientLayer2.frame = CGRect(origin: CGPoint(x: 0, y: (self.imgView.frame.size.height-self.imgView.frame.size.height*0.3)), size: CGSize(width: self.imgView.frame.size.width, height: self.imgView.frame.size.height*0.3))
gradientLayer2.colors = [UIColor.clear.cgColor, UIColor.black.withAlphaComponent(0.7).cgColor]
self.imgView.layer.addSublayer(gradientLayer2)

关于swift - 模糊框架顶部和底部的 UiImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56427486/

相关文章:

ios - 在 iOS 应用程序中为部署目标找到合适的值?

swift - 如何知道快照 View 更有效率?

ios - AWS S3 HeadObject 无法解析 Dispatch_Once

ios - Swift:如何检测平移手势何时被解除/取消?

ios - 如何为自动续订订阅 (iOS) 授予免费月份?

iphone - iPhone 的定位精度会超出职责范围吗?

ios:如何在 View Controller 中保留对象值

ios - 在 iOS 11 上隐藏时状态栏背景消失

ios - 当我点击 UIBarButtonItem 时它会一直高亮

ios - swift iOS : How do I make an Instagram link?