美文网首页
怎么给UIImageView设置模糊效果

怎么给UIImageView设置模糊效果

作者: 这个姑凉儿 | 来源:发表于2018-10-18 10:30 被阅读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;
    }
    
    原图
    效果图

    相关文章

      网友评论

          本文标题:怎么给UIImageView设置模糊效果

          本文链接:https://www.haomeiwen.com/subject/ophziftx.html