๐AdaptiveHStack
SwiftUI โฉ Layout โฉ Adaptive Layout โฉ Size Classes โฉ
โฌ๏ธ ้่ฆ๏ผ ๐ AdaptiveHStack
struct ContentView: View {
@State private var isCompact = true
let text = """
For simplicity's sake, we will focus on conditions based on the horizontal space available: the same concepts can also be applied for vertical space.
"""
var body: some View {
Toggle("is compact", isOn: $isCompact)
.padding()
Spacer()
// ๐ AdaptiveHStack
AdaptiveHStack(threshold: isCompact, alignment: .top) {
// RoundedRectangle
RoundedRectangle(cornerRadius: 16)
.fill(Color.pink)
.frame(maxHeight: 300)
// VStack
VStack {
Text("Title")
.bold()
.font(.title)
Text(text)
.fixedSize(horizontal: false, vertical: true)
}
}
}
}
Last updated
Was this helpful?