Member-only story
✣ SwiftUI: Button ✣
When Expert Use Button In SwiftUI

The button is a fundamental component that is frequently used in SwiftUI. This time, I will provide examples of some commonly used buttons.
There are several tricks that experts use to enhance buttons, such as adding a loading indicator in the center, using haptic feedback, applying gradients, and many more.
In this article, we’ll explore five advanced button examples in SwiftUI:
1. Button with a loading animation
2. Button with haptic feedback
3. Button with a long press gesture
4. Button with a gradient background and shadow
5. Button with a context menu
1. Button loading animation
The first section will display a button with a loading animation. This button is the most essential and also the most frequently used.
@State private var isLoading = false
// Button loading animation
Button(action: {
isLoading.toggle()
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
isLoading.toggle()
}
}) {
HStack {
if isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
}
Text(isLoading ? "Loading..." …