Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Swift Stroke Width

Tags:

path

ios

swift

draw

I have a problem with lineWidth when drawing different shapes in an UIView. All the shapes in the attached pictured should have a lineWidth of 3. Here's the code i used:

 var path:UIBezierPath = UIBezierPath()
 path.moveToPoint(CGPoint(x: 0.0, y: 0.0))
 path.addLineToPoint(CGPoint(x: 0.0, y: 50.0))
 path.lineWidth = 3.0
 path.stroke()

enter image description here As you can see in the pic, only the circle has the true stroke size of 3px. The hands of the clock are all 2px (this is why they're badly aligned).

Can you help me please?

like image 500
Dănuț Mihai Florian Avatar asked Oct 04 '14 06:10

Dănuț Mihai Florian


1 Answers

I figured it out, so i'll post the answer for anyone interested. The line stroke is drawn on every side of the shape. So, in my case, i started drawing at a point (0,0) to (0,50). The left side was clipped, and only the right side was being drawn. Changing the code to

path.moveToPoint(CGPoint(x: 1.0, y: 0.0))
path.addLineToPoint(CGPoint(x: 1.0, y: 50.0))

resolved the problem.

like image 60
Dănuț Mihai Florian Avatar answered Nov 13 '22 18:11

Dănuț Mihai Florian