iOS 8 后使用UIBlurEffect 类和UIVisualEffectView 类添加毛玻璃特效更加便捷,高效。
//创建ImageView
IImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"5"]];
// 创建需要的毛玻璃特效类型
/**
* UIBlurEffectStyleExtraLight,
* UIBlurEffectStyleLight,
* UIBlurEffectStyleDark
*/
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
//添加到要有毛玻璃特效的控件中
UIVisualEffectView *visual = [[UIVisualEffectView alloc] initWithEffect:blur];
visual.frame = imageView.bounds;
[self.view addSubview:imageView];
效果图:
原图:
(1) UIBlurEffectStyleExtraLight
(2) UIBlurEffectStyleLight
(3) UIBlurEffectStyleDark