So I am trying to create a simple set of axes in a custom UIView. Here's the code:
@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()
}
}
In portrait, this turns out fine:
but in landscape, the vertical line is a little bit thicker:
Can anyone help me with why that happens and how to fix it? Thanks!
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.