I hava a custom dropdown list and the top item is a button (because .onTapGesture didn't work with the items I have in the title) for which I want to remove the tap effect (oppacity change of the text). When I tap on selected Item I would like to be the same as a simple Text, no tap effect. enter image description here
I tried .animation(nil) and .buttonStyle(.plain) but with no luck.
Button(action: {
isSelecting = !isSelecting
}) {
HStack {
Text(selectedItem?.title ?? "Select Item")
.animation(.none)
Spacer()
if items.count > 1 {
Image(systemName: "chevron.down")
}
}
.padding(.horizontal)
}
.buttonStyle(.plain)
.animation(nil)
.disabled(items.count < 2)
.onTapGesture {
isSelecting.toggle()
}
You can create a custom ButtonStyle. In makeBody, do not check configuration.isPressed. Always return an accentColor-colored label.
struct NoHighlightButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
// handle button role if necessary
// if configuration.role == .destructive {
// configuration.label.foregroundColor(.red)
// } else {
configuration.label.foregroundColor(.accentColor)
// }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With