继承关系:毛玻璃效果的继承于nsobject 在UIkit框架中所以应用的时候,导入uikit框架即可。
注意点:这套毛玻璃API只是在iOS8.0以后的系统才可以使用,适配需注意。(8.0以前有自己的做法,可百度)
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width,200)];
imageView.image = [UIImage imageNamed:@"你的图片.jpg"];
[self.view addSubview:imageView];
// 创建需要的毛玻璃特效类型
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
[UIVibrancyEffect effectForBlurEffect:blurEffect];
// 毛玻璃view 视图
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
//添加到要有毛玻璃特效的控件中
effectView.frame = imageView.bounds;
//设置模糊透明度
effectView.alpha = .9f;
[imageView addSubview:effectView];