最基本的用法
官网地址:https://developer.apple.com/documentation/swiftui/view/presentationdragindicator(_:)
-
环境 Xcode 15
struct ContentView: View {
@State private var isCreditPresented = false
var body: some View {
Button("顯示半畫面") {
isCreditPresented.toggle()
}
.sheet(isPresented: $isCreditPresented) {
Text("半畫面")
.presentationDetents([.medium, .large])
}
}
}
更改圓角大小
struct ContentView: View {
@State private var isCreditPresented = false
var body: some View {
Button("顯示半畫面") {
isCreditPresented.toggle()
}
.sheet(isPresented: $isCreditPresented) {
Text("半畫面")
.presentationDetents([.medium, .large])
.presentationDragIndicator(.hidden)
.presentationCornerRadius(100.0)
}
}
}
指定高度
struct ContentView: View {
@State private var isCreditPresented = false
var body: some View {
Button("顯示半畫面") {
isCreditPresented.toggle()
}
.sheet(isPresented: $isCreditPresented) {
Text("半畫面")
.presentationDetents([.height(100)])
.presentationDragIndicator(.hidden)
}
}
}