【问题标题】:Programmatically create a UIView with color gradient with blur effect in ios在 ios 中以编程方式创建具有颜色渐变和模糊效果的 UIView
【发布时间】:2018-09-21 07:13:02
【问题描述】:

我正在尝试使用目标 c 创建一个具有颜色渐变和模糊效果(360 度)的 UIview。

我只能在一个方向上做这种渐变效果。我需要像 360 度矩形一样的输出。

这是我的代码

CAGradientLayer *gradient = [CAGradientLayer layer];

gradient.frame = view.bounds;
gradient.colors = @[(id)[UIColor whiteColor].CGColor, (id)[UIColor blackColor].CGColor];

[view.layer insertSublayer:gradient atIndex:0];

【问题讨论】:

    标签: ios objective-c uiview cagradientlayer


    【解决方案1】:

    您可以像您的代码一样应用渐变层,然后添加下面的代码而不是查看它。

       if (!UIAccessibilityIsReduceTransparencyEnabled()) {
        self.view.backgroundColor = [UIColor clearColor];
    
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    //always fill the view
    blurEffectView.frame = self.view.bounds;
    blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    [self.view addSubview:blurEffectView]; //if you have more UIViews, use an insertSubview API to place it where needed
    } else {
        self.view.backgroundColor = [UIColor blackColor];
    }
    

    我希望它会起作用。

    【讨论】:

      猜你喜欢
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      • 2013-10-20
      相关资源
      最近更新 更多