Primary button press
A standard call-to-action button ("Continue", "Add to cart") confirms the press.
import SwiftUI
struct PrimaryButton: View {
let title: String
let action: () -> Void
@State private var pressCount = 0
var body: some View {
Button {
pressCount += 1
action()
} label: {
Text(title)
.font(.headline)
.frame(maxWidth: .infinity)
.padding()
.background(.blue, in: RoundedRectangle(cornerRadius: 14))
.foregroundStyle(.white)
}
.sensoryFeedback(.impact(weight: .medium), trigger: pressCount)
}
} let button = UIButton(configuration: .filled())
button.setTitle("Continue", for: .normal)
let haptic = UIImpactFeedbackGenerator(style: .medium)
button.addAction(UIAction { _ in haptic.prepare() }, for: .touchDown)
button.addAction(UIAction { _ in
haptic.impactOccurred()
// perform the action
}, for: .touchUpInside)