I am trying to draw graphs so they look the same on all devices.
To do this, I have first found the width of my view (which has been set in AutoLayout to be half the width of the superview).
Then in code I have set a variable unitDim
to be one thousandth of that width:
func setDimension() {
unitDim = Float(self.bounds.width)/1000
}
Then, instead of drawing in terms of points, I have used unitDim.
e.g. axisLength = 400 * unitDim
.
I have set the values of these in a function setDimensions()
which is called from the view controller for that view.
So my code in the draw function is as shown below:
So I would expect my axis to take up 40% of the view width. But when I view the axes in iPad and iPhone I get different results. I cannot figure out why this is. Below is how it appears on iPad simulator:
and below is how it appears on iPhone simulator: