struct ContentView: View { var body: some View { VStack { Text("DevTechie") .font(.largeTitle) Text("ViewThatFits is a container view introduced with SwiftUI 4 and iOS 16. ViewThatFits holds collection of child views and displays a view depending upon the available size. It does so by evaluating child views in the order they are defined and selects the child view whose size is ideal to fit in within the constrained space. We provide views in the order we prefer, meaning we define in the order of largest to smallest view and ViewThatFits picks a child view depending upon the space provided by parent view.") .font(.title3) .padding() .frame(maxWidth: .infinity) .background(Color.orange) .layoutPriority(1) ViewThatFits { VStack { Button(action: {}) { Label("Like", systemImage: "hand.thumbsup") .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) Button(action: {}) { Label("Subscribe", systemImage: "heart") .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) } HStack { Button(action: {}) { Label("Like", systemImage: "hand.thumbsup") .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) Button(action: {}) { Label("Subscribe", systemImage: "heart") .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) } } } } }
struct ContentView: View { var body: some View { VStack { Text("DevTechie") .font(.largeTitle) Text("ViewThatFits is a container view introduced with SwiftUI 4 and iOS 16. ViewThatFits holds collection of child views and displays a view depending upon the available size. It does so by evaluating child views in the order they are defined and selects the child view whose size is ideal to fit in within the constrained space. We provide views in the order we prefer, meaning we define in the order of largest to smallest view and ViewThatFits picks a child view depending upon the space provided by parent view.") .font(.title) .padding() .frame(maxWidth: .infinity) .background(Color.orange) .layoutPriority(1) ViewThatFits { VStack { Button(action: {}) { Label("Like", systemImage: "hand.thumbsup") .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) Button(action: {}) { Label("Subscribe", systemImage: "heart") .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) } HStack { Button(action: {}) { Label("Like", systemImage: "hand.thumbsup") .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) Button(action: {}) { Label("Subscribe", systemImage: "heart") .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) } } } } }
With that we have reached the end of this article. Thank you once again for reading. Subscribe to our weekly newsletter at https://www.devtechie.com