change Toast position
rami-almofleh opened this issue · 2 comments
rami-almofleh commented
Pre-requisites:
- No, I did not find what I was looking for
Feature Suggestion
Is there any Idee how we change the position of Toast
toast was always displayed in the middle and we do not want that
best if you can change the position of the toast, would it be possible to do it?
quanshousio commented
If you're using built-in toast views, there's no straightforward way to change the toast position as the view is implemented in that way. However, if you're using normal SwiftUI views, you can use HStack
/VStack
combining with Spacer
to change the position of a view as usual. Here's an example of showing a success toast on the middle top of the screen.
struct ContentView: View {
@State private var presentingToast: Bool = false
var body: some View {
Button {
presentingToast = true
} label: {
Text("Tap me")
}
.toast(isPresented: $presentingToast, dismissAfter: 2.0) {
VStack {
HStack {
Spacer()
// toast
VStack {
Image(systemName: "checkmark.circle.fill")
.resizable()
.frame(width: 36, height: 36)
.foregroundColor(.green)
Text("Success")
.fixedSize()
.font(.headline)
.foregroundColor(.secondary)
.multilineTextAlignment(.center)
}
.padding(20)
.background(Color(.secondarySystemBackground))
.cornerRadius(9)
Spacer()
}
Spacer()
}
.padding()
}
}
}
quanshousio commented
This issue has been closed due to inactivity. Please feel free to reopen it if you have any further questions.