This article was written using Xcode 14 and iOS 16
Introduction
Using SwiftUI to build next-generation apps means that it’s super important to be able to customize the size of your Views based on the platform you’re deploying on.
Apple has released the presentationDetents
modifier API’s to SwiftUI so it’s super easy to deploy sheets or similar with various sizes.
struct ContentView: View {
@State private var showSettings = false
var body: some View {
Button("View Settings") {
showSettings = true
}
.sheet(isPresented: $showSettings) {
SettingsView()
.presentationDetents([.medium, .large])
}
}
}
struct SettingsView: View {
var body: some View {
Text("Settings Coming Soon")
}
}
Take your example here, you’re deploying a very basic View
that displays some Text
, you’re displaying it using a sheet View
type but you can define the presentationDetents
.
The options available are:
.medium
.large
.height()
.fraction
You can go ahead and play around with the various options.