'How can I present a small page sheet with SwiftUI?
I'm developing an app for iPad with SwiftUI. I want to present a page sheet but with a smaller size. I'm using but I can't change the width of the page sheet.
.sheet(
isPresented: self.$isEditing,
) {
Text("My page sheet view")
}
The result is :
How can I have the Apple shortcut app modal size ?
Maybe it's a proprietary custom view from Apple not available with UIKit... Thank you very much
Solution 1:[1]
At the moment, you can use an actionSheet (iOS 14 or earlier) / confirmationDialog (iOS 15 or later) which is much smaller or you can create your own custom-made sheet maybe with usage of SheeKit.
For the case that an actionSheet / confirmationDialog is enough:
@State private var showingConfirm: Bool = false
@State private var actionSelection = ""
..
Group {
Button(action: {
showingConfirm.toggle()
}, label: {
Label("Demo")
})
}
// iOS 14
.actionSheet(isPresented: $showingConfirm, content: {
let action1 = ActionSheet.Button.default(Text("First action")) {
actionSelection = "First"
}
let action2 = ActionSheet.Button.default(Text("Second action")) {
actionSelection = "Second"
}
return ActionSheet(title: Text("Action Sheet"), message: Text("Message"), buttons: [action1, action2])
})
// or for iOS 15
.confirmationDialog("Action Sheet", isPresented: $showingConfirm, titleVisibility: .visible) {
Button("First action") {
actionSelection = "First"
}
Button("Second action") {
actionSelection = "Second"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hendrik |