A SwiftUI view that triggers a click after holding it for a set amount of time
HoldToClickButton(
label: {
Text("Hold To Click")
.fontWeight(.bold)
.foregroundColor(.black)
},
onHoldEnd: {
// Do something when clicked
}
)
The following optional parameters are available
HoldToClickButton(
fillColor: Color = Color.orange,
borderColor: Color = Color.black,
borderWidth: CGFloat = 2.0,
holdDuration: TimeInterval = 1.5,
cancelDuration: TimeInterval = 0.3,
label: @escaping () -> Label,
onHoldBegin: (() -> Void)? = nil,
onHoldEnd: (() -> Void)? = nil,
onHoldCancel: (() -> Void)? = nil
)
- Swift >= 5.7
- iOS >= 14
- macOS >= 13
- watchOS >= 7
HoldToClickButton is available as a Swift package.
Include HoldToClickButton.swift
in your project
HoldToClickButton is available under the MIT license. See LICENSE
for more info.