【发布时间】:2014-12-09 18:14:52
【问题描述】:
我正在尝试像这样使用 Swift 在 UIView 上画一条线:
CGContextSetLineWidth(context, 1.0)
CGContextBeginPath(context)
CGContextMoveToPoint(context, x1, y1)
CGContextAddLineToPoint(context, x2, y2)
CGContextStrokePath(context)
但绘制的线是 2 像素宽。我尝试了另一种方式:
CGContextSetLineWidth(context, 0.5)
CGContextBeginPath(context)
CGContextMoveToPoint(context, x1, y1)
CGContextAddLineToPoint(context, x2, y2)
CGContextStrokePath(context)
但结果是一样的。 我在做什么错以及如何使用 Swift 在 UIView 上绘制 1 像素宽的线?
【问题讨论】:
-
只是好奇;你怎么知道它是 2 像素?
-
不错的重复问题候选,但我很惊讶没有完整且正确的标记答案。不过,我可能找不到另一个重复项。
-
@Unheilig,很简单!我做了一个截图并放大了它。
标签: ios swift uiview drawing line