【问题标题】:How to set corner radius value with CAShaperLayer?如何使用 CAShaperLayer 设置拐角半径值?
【发布时间】:2017-10-04 12:38:50
【问题描述】:

我用 UIBeizerPath 画了一条垂直线,我需要这条线的圆角半径为 5。我试图回忆 [pathLayer setCornerRadius: 5]; 但我没有得到结果......你能帮帮我吗?如何分配拐角半径值?这是我使用的代码

    // crea le barre del grafico e gli assegna l'altezza della label y corrispondente
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(xPaddingFromYAxis +spaceBetweenBar *j, 200)];
    [path addLineToPoint:CGPointMake(xPaddingFromYAxis +spaceBetweenBar *j,  yLabelValue.center.y )];

    CAShapeLayer *pathLayer = [CAShapeLayer layer];
    pathLayer.frame = self.bounds;
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = [UIColor darkGrayColor].CGColor;
    pathLayer.fillColor = nil;
    pathLayer.lineWidth = 50;
    [pathLayer setCornerRadius:5];
    pathLayer.masksToBounds = NO;
    [scroll.layer addSublayer:pathLayer];

【问题讨论】:

    标签: ios objective-c uibezierpath cashapelayer cornerradius


    【解决方案1】:

    您需要将掩码设置为“是”。 pathLayer.masksToBounds = YES;


    试试这个看看:

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(xPaddingFromYAxis +spaceBetweenBar *j, 200)];
    [path addLineToPoint:CGPointMake(xPaddingFromYAxis +spaceBetweenBar *j,  yLabelValue.center.y )];
    
    CAShapeLayer *pathLayer = [CAShapeLayer layer];
    pathLayer.frame = self.bounds;
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = [UIColor darkGrayColor].CGColor;
    pathLayer.fillColor = nil;
    pathLayer.lineWidth = 50;
    [pathLayer setCornerRadius:5];
    pathLayer.masksToBounds = YES;
    [scroll.layer addSublayer:pathLayer];
    

    【讨论】:

    • 我尝试使用 maskToBound = YES 但该行消失了,您再也看不到它了...为什么?
    • 可以分享一下截图吗?有无pathLayer.masksToBounds?它对我有用。
    • 我创建代码的方式是否有误?你想让我在 pastebin 链接中向你展示所有内容吗?
    • 将圆角半径值从 5.0 更新到 0.5(查看结果并逐渐增加......)
    • 你能分享我的示例(完整)源代码吗?你在你的代码中有什么。这样我就可以轻松解决了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多