You can modify the highlight/press state of Buttons with SwiftUI by implementing your own ButtonStyle which modifies the label based on the isPressed state.
In iOS 13, this was animated both on touch down and touch up. In iOS 14 beta, it does not animate on press down, only up. I want to enable animation on touch down. How can this be done?
struct CustomButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.5 : 1)
}
}
struct CustomButton: View {
var body: some View {
Button(action: {}) {
RoundedRectangle(cornerRadius: 10)
.frame(width: 100, height: 100)
.foregroundColor(.pink)
}
.buttonStyle(CustomButtonStyle())
}
}

Simply define an explicit animation in your button style make body.
for example, you can add .animation(.easeOut) below .scaleEffect(configuration.isPressed ? 0.5 : 1)
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