所以我试图在自定义UIView中创建一组简单的轴。这是代码:
@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()
}
}
在肖像方面,结果很好:
但在横向上,垂直线稍微厚一些:
任何人都可以帮我解释为什么会发生这种情况以及如何解决这个问题?谢谢!
答案 0 :(得分:2)
I figured it out in the end. Right now, the mode for the custom view was set at "Scale to Fill". I just had to change it to "redraw" so it would run drawRect again.