0

Reference Image

I am having an image at my view controller, while on top of the image view I am having some label but due to label text visibility I need to blur the top and bottom of the UIImageView ignorer to show the text clearly.

I have attached the screenshot for my design ignorer to get a clear cut idea.

Please referent the image for the right output.

RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70
  • Have you any working examples of doing this? I'd guess that "out-of-the-box" blurs use pixels *both* vertical *and* horizontal. You *could* pretty easily build your own `CIFilter` (or more accurately, `CIKernel` to do things vertically. But you've tagged this [uiblureffect] and I'm pretty sure it doesn't work that way. Finally, are you talking **blur** or **darken** to show white text more prominently? There's a difference - and if I recall, other Q&A here that address the best ways of doing that. –  Jun 03 '19 at 14:26
  • please tell me what will be the better solution to create this kind of image view. – Karthick TM Jun 04 '19 at 06:29

1 Answers1

0

Add this code to your 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)
VRAwesome
  • 4,721
  • 5
  • 27
  • 52