Created
April 20, 2020 19:29
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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