【问题标题】:How to make CALayer border with Gradient or Multiple Colors?如何使用渐变或多种颜色制作 CALayer 边框?
【发布时间】:2015-12-30 11:35:53
【问题描述】:
        CALayer *rightBorder = [CALayer layer];
        rightBorder.borderColor = [UIColor redColor].CGColor;
        rightBorder.borderWidth = 1;
        rightBorder.frame = CGRectMake(-1, -1, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)+2);

        [self.layer addSublayer:rightBorder];

我正在像上面那样制作 WebView 的边框。这里的self继承自UIWebView。

如何改变

rightBorder.borderColor = [UIColor redColor].CGColor;

渐变色,所以我的颜色应该一半是蓝色,一半是白色。

在这里,我将 RED 颜色应用于我的 WebView 的边框。不过我想要多色(2 色)或渐变色。

谢谢。

【问题讨论】:

    标签: ios uiwebview gradient


    【解决方案1】:

    为了在具有渐变效果的图层中显示不同的颜色,我分享了我的代码的一种方法,您必须为此使用 CAGradientLayer,

    -(void)addGradiantColor:(UIView *)view;
    {
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.frame = view.frame;
         //  gradientLayer.startPoint = CGPointMake(0.0,0.0);
         //  gradientLayer.endPoint = CGPointMake(1.0,1.0);
        NSMutableArray *colors = [NSMutableArray array];
        [colors addObject:(id)[[UIColor colorWithRed:134.0/255.0 green: 234.0/255.0   blue:63.0/255.0 alpha:1.0] CGColor]];
        [colors addObject:(id)[[UIColor colorWithRed:215.0/255.0 green: 82.0/255.0 blue:76.0/255.0 alpha:1.0] CGColor]];
        gradientLayer.colors = colors;
        [view.layer addSublayer:gradientLayer];   
    }
    

    【讨论】:

    • 贝塞尔路径有可能吗?
    • 我们可以将它与 UIBezierPath 一起应用,实际上我并没有太多想法,但我有一个演示,其中我使用了 UIBezierPath,它太长了,无法在评论中分享,我不知道如何分享
    • 把你的邮箱给我,我会发送那个方法
    • @ioslearner,我认为这将由 UIBezierPath 完成,但我想要简单的方法,如果有的话,所以我的脑海中点击了 Gradient。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-11
    相关资源
    最近更新 更多