iOS 8.0之后,系统提供了自带的模糊效果:
UIImageView *imageview = [[UIImageView alloc] init];
imageview.frame = CGRectMake(10, 100, self.view.frame.size.width-20, 400);
imageview.image = [UIImage imageNamed:@"test.jpg"];
imageview.contentMode = UIViewContentModeScaleAspectFit;
imageview.userInteractionEnabled = YES;
[self.view addSubview:imageview];
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
effectview.frame = CGRectMake(0, 0, imageview.frame.size.width, 400);
[imageview addSubview:effectview];
原图:
添加模糊之后: