ios - 如何使用 CAShaperLayer 设置圆角半径值?

标签 ios objective-c uibezierpath cashapelayer cornerradius

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

enter image description here

最佳答案

您需要将掩码绑定(bind)设置为"is"。 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];

关于ios - 如何使用 CAShaperLayer 设置圆角半径值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46565095/

相关文章:

ios - 如何在 ios swift 4 中获取可用的 wifi 网络

iOS8 对新应用的要求,这到底是什么意思

ios - 在 UIView 周围绘制 CALayer 边框

iOS 屏幕绘图最佳实践

ios - dequeueReusableCellWithIdentifier 不返回自定义单元格

iphone - 如何让 Sprite 跟随轨迹?

ios - 将应用发送到后台时执行NSLog

java - MongoDB 复杂存储过程可以与 Java Web 服务一起使用吗

ios - 从一个viewController调用另一个 View Controller 的IBAction

swift - 使用 UIBezierPath 的带有圆角的 TableView 页眉和页脚