简体   繁体   中英

iOS Swift Stroke Width

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()

在此输入图像描述 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM