首页 热点资讯 义务教育 高等教育 出国留学 考研考公
您的当前位置:首页正文

图片模糊化

2024-12-18 来源:化拓教育网
Simulator 效果图.png

实现方法很简单,就是在imageView上面添加一个UIVisualEffectView

OC代码

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    imageView.image = [UIImage imageNamed:@"aaa"];
    [self.view addSubview:imageView];

    UIBlurEffect *blureffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blureffect];
    effectView.frame = imageView.bounds;
    [imageView addSubview:effectView];
}

Swift


let imgBack = UIImageView(image: UIImage.init(named: "aaa"))
imgBack.frame = view.bounds
view.addSubview(imgBack)
        
let blurEffect = UIBlurEffect(style: .light)
let effectView = UIVisualEffectView(effect: blurEffect)
effectView.frame = imgBack.bounds
imgBack.addSubview(effectView)
显示全文