4

I used this example to draw dashed line on uiview:

 UIBezierPath *path = [UIBezierPath bezierPath];
 //draw a line
 [path moveToPoint:yourStartPoint]; //add yourStartPoint here
 [path addLineToPoint:yourEndPoint];// add yourEndPoint here
 [path stroke];

 float dashPattern[] = {1,1,1,1}; //make your pattern here
 [path setLineDash:dashPattern count:4 phase:0];

 UIColor *fill = [UIColor blueColor];
 shapelayer.strokeStart = 0.0;
 shapelayer.strokeColor = fill.CGColor;
 shapelayer.lineWidth = 7.0;
 shapelayer.lineJoin = kCALineJoinMiter;
 shapelayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:10], nil];
 shapelayer.lineDashPhase = 3.0f;
 shapelayer.path = path.CGPath;

it works, but problem is that even though I set my uiview height 1, the line I get is quite thick. enter image description here

is it possible to make it thinner?

Community
  • 1
  • 1
arsena
  • 1,935
  • 19
  • 36

1 Answers1

5

You can change the thickness of the line at this part of your code:

shapelayer.lineWidth = 7.0;

Change the 7.0 to whatever thickness you would like your line to have.

Alfonso
  • 8,386
  • 1
  • 43
  • 63
  • WTF :/ why the hell does the property named lineWIDTH change the HEIGHT of it? :( anyway, thanks a lot :| – arsena Dec 02 '16 at 08:54
  • 1
    because the `line` have width not height, englishically. ;) – Bista Dec 02 '16 at 09:09
  • 'lineThickness' would make sense – RJR Dec 02 '16 at 09:37
  • @Mr.Bista if line is 1D then yes, but this line doesn't look like one; anyway, as @RJR said `lineThickness` would make much more sense. – arsena Dec 02 '16 at 10:11
  • I think term Thickness is used for 3D Object, else it will be Width. **Source:** Google `Thick vs Width -> Images` – Bista Dec 02 '16 at 10:31