美文网首页iOS技术文章
毛玻璃效果-UIView模糊效果✨

毛玻璃效果-UIView模糊效果✨

作者: LeaderBiao | 来源:发表于2016-06-28 19:13 被阅读502次
  • 版权声明:本文为博主原创文章,未经博主允许不得转载。
  // 定义毛玻璃效果
    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```


![](http:https://img.haomeiwen.com/i838345/1ffaf7aac1128f77?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

之后还有你想把你的图片模糊也可以这样添加:

```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];```

相关文章

网友评论

    本文标题:毛玻璃效果-UIView模糊效果✨

    本文链接:https://www.haomeiwen.com/subject/umvtjttx.html