Skip to content

Instantly share code, notes, and snippets.

@pyxn
Created April 20, 2020 19:29
Show Gist options
  • Save pyxn/f81e26ddb856125a861ce5dea5dc11bb to your computer and use it in GitHub Desktop.
Save pyxn/f81e26ddb856125a861ce5dea5dc11bb to your computer and use it in GitHub Desktop.
Custom DeviceSize class template which creates a scale of 21 sizes based on a scale (in this case, the Silver Ratio).
import SwiftUI
class DeviceSize {
var scale: [CGFloat] {
var silverRatioArray: [CGFloat] = [0]
for i in 0 ... 21 {
if i > 1 {
silverArray[i] = silverArray[i - 1] * (1 + sqrt(2))
} else {
silverArray[i] = 1
}
}
return silverRatioArray
}
var size: [CGFloat] {
let displayFactor: CGFloat = 420
var scaledArray: [CGFloat] = [0]
for i in 0 ... 21 {
size[i] = displayFactor * scale[i]
if i < 21 { size.append(size[i]) }
}
return scaledArray
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment