- 版權聲明:本文為博主原創文章,未經博主允許不得轉載。
// 定義毛玻璃效果
UIBlurEffect * blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView * effe = [[UIVisualEffectView alloc]initWithEffect:blur];
effe.frame = CGRectMake(50, 90, self.view.frame.size.width - 100, 400);
// 把要添加的視圖加到毛玻璃上
UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
but.backgroundColor = [UIColor redColor];
[effe addSubview:but];
[self.view addSubview:effe];
//他的效果是枚舉,有三種
UIBlurEffectStyleExtraLight
UIBlurEffectStyleLight
UIBlurEffectStyleDark```

之后還有你想把你的圖片模糊也可以這樣添加:
```objc
// 定義需要毛玻璃化的圖片
UIImageView * image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"2.png"]];
image.frame = CGRectMake(100, 100, 100, 100);
// 定義毛玻璃效果
UIBlurEffect * blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView * effe = [[UIVisualEffectView alloc]initWithEffect:blur];
effe.frame = CGRectMake(50, 90, self.view.frame.size.width - 100, 400);
// 添加毛玻璃
[image addSubview:effe];
[self.view addSubview:image];```
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。