1
所以我想在一个自定义的UIView创建一个简单的坐标轴上。下面的代码:UI贝塞尔路径改变线宽。
@IBDesignable
class GraphingView: UIView {
@IBInspectable
var axesColor : UIColor = UIColor.redColor() { didSet{ setNeedsDisplay() } }
@IBInspectable
var lineWidth : CGFloat = 1.0 { didSet{ setNeedsDisplay() } }
var origin : CGPoint{
return convertPoint(center, fromView: superview)
}
override func drawRect(rect: CGRect) {
let axesPath = UIBezierPath()
axesPath.moveToPoint(CGPoint(x: 0, y: origin.y))
axesPath.addLineToPoint(CGPoint(x: bounds.width, y: origin.y))
axesPath.moveToPoint(CGPoint(x: origin.x, y: 0))
axesPath.addLineToPoint(CGPoint(x: origin.x, y: bounds.height))
axesPath.lineWidth = lineWidth
axesColor.set()
axesPath.stroke()
}
}
在肖像,这原来罚款:
但在景观,垂直线是一点点厚:
任何人都可以帮我解释为什么会发生这种情况,以及如何解决它?谢谢!
我没有想到为此找到一个解决方案,但你的问题和答案救了我一把ha。谢谢 – Eyzuky