怎么给UIImageView设置模糊效果

2018-10-18  本文已影响0人  这个姑凉儿
#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong) UIImageView *bgImage;//背景
@property (nonatomic, strong) UIVisualEffectView *visualEffectView;//背景的模糊效果

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.bgImage];
}

-(UIImageView *)bgImage{
    if (!_bgImage) {
        _bgImage = [[UIImageView alloc] initWithFrame:self.view.bounds];
        _bgImage.image = [UIImage imageNamed:@"timg"];
        //模糊的效果
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blur];
        visualEffectView.frame = _bgImage.frame;
        _visualEffectView = visualEffectView;
        [_bgImage addSubview:visualEffectView];
    }
    return _bgImage;
}
原图
效果图
上一篇下一篇

猜你喜欢

热点阅读