用到几个类
1. UIBlurEffect 常用
2. UIVisualEffectView 常用
3. UIVibrancyEffect 主要用于放大和调整UIVisualEffectView
视图下面的内容的颜色
UIVibrancyEffect
只有一个初始化方法
+ (UIVibrancyEffect *)effectForBlurEffect:(UIBlurEffect *)blurEffect;
代码
UIImage *image = [UIImage imageNamed:@"woodBridge"];
float scale = image.size.width / image.size.height;
UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
iv.image = image;
[self.view addSubview:iv];
//1. 创建一个毛玻璃
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc]initWithEffect:effect];
visualEffectView.alpha = 0.9;
[visualEffectView setFrame:CGRectMake(0, 200, 375, 200)];
[self.view addSubview:visualEffectView];
//2. 利用UIVibrancyEffect实现一些效果
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:effect];
UIVisualEffectView *blurView = [[UIVisualEffectView alloc]initWithEffect:vibrancyEffect];
[blurView setTranslatesAutoresizingMaskIntoConstraints:NO];
[visualEffectView.contentView addSubview:blurView];
[blurView setFrame:visualEffectView.bounds];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
label.center = blurView.center;
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
label.textAlignment = NSTextAlignmentCenter;
label.text = @"Do by heat";
label.font = [UIFont fontWithName:@"Baskerville-Bold" size:30];
label.tintColor = [UIColor orangeColor];
[blurView.contentView addSubview:label];
网友评论