UIVisualEffectView

来源:互联网 发布:淘宝网app 电脑 编辑:程序博客网 时间:2024/05/24 05:41

在需要模糊的UIView上,添加一个UIVisualEffectView对象即可。

效果如下图:

\

代码如下:

 

UIImageView *imageview = [[UIImageView alloc] init];

imageview.frame = CGRectMake(10, 100, 300, 300);

imageview.image = [UIImage imageNamed:@"2"];

imageview.contentMode = UIViewContentModeScaleAspectFit;

imageview.userInteractionEnabled = YES;

[self.view addSubview:imageview];

 

UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];

effectview.frame = CGRectMake(0, 0, imageview.size.width/2, 300);

 

[imageview addSubview:effectview];

 

 

UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];

btn.frame = CGRectMake(10, 50, 100, 40);

[btn setTitle:@"btn" forState:UIControlStateNormal];

[effectview.contentView addSubview:btn];


0 0