Steve Harris Steve Harris - 1 year ago 83
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download