Sometimes, I need to make device-specific adjustments to layouts. For example, I may need to reduce spacing on an iPhone with a smaller screen or increase spacing on the largest screens. With UIKit (and even Interface Builder) it was easy to make layout exceptions for specific size classes. What is the best way to do conditional device-specific layouts with SwiftUI?
I've been scouring the SwiftUI documentation, and haven't found a way to access and use this type of information in layouts.
Below is an example for an Apple Watch app. Per Apple's design guidelines, I'm adding 8.5 points of padding to the left and right on the 40mm Series 4. However, the 44mm should have 9.5 points of padding, and any Apple Watch older than Series 4 should have no padding.
What is the best way to achieve this with SwiftUI?
struct ContentView : View {
var body: some View {
HStack {
Text("Hello World")
}.padding([.horizontal], 8.5)
}
}