iOS achieves image Gaussian blur effect

The rendering
Please add a picture description
uses UIVisualEffectView

Implementation code

- (UIVisualEffectView *)bgEffectView{
    if(!_bgEffectView){
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        _bgEffectView = [[UIVisualEffectView alloc] initWithEffect:blur];
    }
    return _bgEffectView;
}

Cover the bgEffectView on top of the imageview

- (UIImageView *)bannerView
{
    if (!_bannerView) {
        _bannerView = [[UIImageView alloc] init];
        _bannerView.backgroundColor = [UIColor redColor];
    }
    return _bannerView;
}

- (UIVisualEffectView *)bgEffectView{
    if(!_bgEffectView){
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        _bgEffectView = [[UIVisualEffectView alloc] initWithEffect:blur];
    }
    return _bgEffectView;
}


   [self addSubview:self.bannerView];
    [self addSubview:self.bgEffectView];

Guess you like

Origin blog.csdn.net/LIUXIAOXIAOBO/article/details/132161561