美文网首页
iOS 毛玻璃

iOS 毛玻璃

作者: 霸_霸霸 | 来源:发表于2018-08-21 13:43 被阅读38次
image.png

用到几个类

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

http://southpeak.github.io/2015/05/31/ios-techset-2/

相关文章

网友评论

      本文标题:iOS 毛玻璃

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