Perseus
Perseus

Reputation: 1588

Make the UIImageView blur

I am having a View1 which has a UIImageView where I am loading a UIImage. When I am pressing a button in the View1 , I am adding a subview called View2 which has 2 buttons.

And I am making my second view as transparency using the alpha value like below.

[_view2 setBackgroundColor:[UIColor clearColor]];
_imageView.alpha = 0.4;

That is ok. But What I want to do is, When I am adding the second subview, the first view is visible. Decreasing the alpha value will result in brightness of it. But I want to display the imageview in the first view little blur. I need to set the alpha value as well as make the background image view blur. Can Anyone tell me how to do it ?

Upvotes: 0

Views: 1861

Answers (2)

levin varghese
levin varghese

Reputation: 810

Swift version

 public extension UIImageView {

   public func blur(withStyle style: UIBlurEffectStyle = .light) {
    let blurEffect = UIBlurEffect(style: style)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    blurEffectView.frame = bounds
    blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] // for supporting device rotation
    addSubview(blurEffectView)
    clipsToBounds = true
  }

}

Upvotes: 0

sergio
sergio

Reputation: 69027

Give a look at this class that promises to implement blurring for images under iOS: https://github.com/tomsoft1/StackBluriOS.

Upvotes: 2

Related Questions