- 版權(quán)聲明:本文為博主原創(chuàng)文章特石,未經(jīng)博主允許不得轉(zhuǎn)載。
// 定義毛玻璃效果
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];```
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者