Steve Harris Steve Harris - 2 months ago 13
Swift Question

How to set line width for different devices

I am drawing graphs for an app which is for iPad and iPhone.
I have managed to scale all the dimensions so that the graphs, axes, etc. scale correctly for different devices.
But I am unsure how to scale line widths.
So if I write:


the line will appear quite thick on an iPhone 5 but thinner on an iPad. I would like to make it look thinner on the smaller devices.


Change the LineWidth as dynamic value based on the Graph or Screen Width, try like this

iPhone 5

let graphWidth = 320.0 //set screenWidth
var lineWidth = (graphWidth*(1.5/100)) // here you can change the percentage value
print("Line Width == > \(Int(lineWidth))") //Line Width == > 4

iPhone 6

let graphWidth = 375.0 // be dynamic graphWidth = graph width
var lineWidth = (graphWidth*(1.5/100))
print("Line Width == > \(Int(lineWidth))") //Line Width == > 5