2

i drew a vertical line with UIBeizerPath and i need this line to have a corner radius with a value of 5. i tried to recall [pathLayer setCornerRadius: 5]; but I do not get results ... Can you help me? how can I assign a corner radius value? this is the code I use

    // 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

Krunal
  • 77,632
  • 48
  • 245
  • 261
kAiN
  • 2,559
  • 1
  • 26
  • 54

1 Answers1

1

You need to set mask to bound as 'YES'. pathLayer.masksToBounds = YES;


Try this and see:

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];
Krunal
  • 77,632
  • 48
  • 245
  • 261
  • I tried with maskToBound = YES but the line disappears, you can not see it anymore ... why? – kAiN Oct 04 '17 at 13:00
  • Can you please share screenshot? With and without `pathLayer.masksToBounds`? It works for me. – Krunal Oct 04 '17 at 13:03
  • Could I have misplaced the way I created the code? do you want me to show you everything in a pastebin link? – kAiN Oct 04 '17 at 13:07
  • Update corner radius value from 5.0 to 0.5 (see result and gradually increase it....) – Krunal Oct 05 '17 at 03:18
  • Can you share me sample (full) source code? what you've in your code. So I can solve it easily – Krunal Oct 05 '17 at 16:56
  • if you think there are errors in the code can you tell me? sometimes i'm not sure of my code – kAiN Oct 05 '17 at 17:00