I am trying to apply a frosted glass effect in a UIImageView.
I tried to implement what I\'ve found in this question, but the result wasn\'t accepta
Solution for iOS 7 and 8, without using CoreImage or CoreGraphics at all:
- (void)addBlurToView:(UIView *)view {
UIView *blurView = nil;
if([UIBlurEffect class]) { // iOS 8
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurView.frame = view.frame;
} else { // workaround for iOS 7
blurView = [[UIToolbar alloc] initWithFrame:view.bounds];
}
[blurView setTranslatesAutoresizingMaskIntoConstraints:NO];
[view addSubview:blurView];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[blurView]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(blurView)]];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[blurView]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(blurView)]];
}
(assuming you're not targeting versions older than iOS 7; if you are, you'll have to test for the iOS version in the else block)
This solution applies to any view, not only images.