If I have a VStack with limited height and the contents of the VStack require more height than what's available, is there a way I can control which items get clipped?
I created the short sample below to illustrate.
I'd like "Bottom" to be clipped instead of the black rectangle when the toggle is set to "Open".
I've tried .fixedSize, .layoutPriority and a number of other things.
import SwiftUI
struct ContentView: View {
@State var isOpen: Bool = false
var body: some View {
container
}
@ViewBuilder var container: some View {
VStack {
header
content
}
.frame(width: 300, height: 110)
.background(.gray)
.cornerRadius(20)
}
@ViewBuilder var header: some View {
RoundedRectangle(cornerRadius: 5)
.frame(width: 50, height: 10)
}
@ViewBuilder var content: some View {
VStack(alignment: .leading) {
Picker("mypicker", selection: $isOpen) {
Text("Open").tag(true)
Text("Closed").tag(false)
}
.pickerStyle(.segmented)
if isOpen {
Text("Top")
Text("Middle")
Text("Bottom")
}
}
}
}







