IOS Swift Stroke Width

I have a problem with lineWidth when drawing different shapes in a UIView. All shapes in the attached image should have a line width of 3. Here is 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 figure, Only the circle has a true stroke size of 3px. The hands of the watch are all 2px (which is why they are poorly aligned).

Can you help me?

+5
source share
1 answer

I understood, so I will send an answer to everyone who is interested. A line stroke is drawn on each side of the form. So, in my case, I started drawing at the point (0,0) to (0,50). The left side was cropped and only the right side was painted. Change code to

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

solved the problem.

+4
source

Source: https://habr.com/ru/post/1203987/


All Articles