实现方法很简单,就是在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)