Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/no-comment/slidebutton
SwiftUI package that provides a customizable slide button that can be swiped to unlock or perform an action
https://github.com/no-comment/slidebutton
swift swiftui
Last synced: 4 days ago
JSON representation
SwiftUI package that provides a customizable slide button that can be swiped to unlock or perform an action
- Host: GitHub
- URL: https://github.com/no-comment/slidebutton
- Owner: no-comment
- License: mit
- Created: 2023-04-16T16:55:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-23T18:50:34.000Z (6 months ago)
- Last Synced: 2024-10-05T13:02:05.276Z (about 1 month ago)
- Topics: swift, swiftui
- Language: Swift
- Homepage:
- Size: 17.6 KB
- Stars: 25
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SlideButton
SlideButton is a SwiftUI package that provides a customizable slide button that can be swiped to unlock or perform an action. The button consists of a background color, a title, an icon, and an indicator that can be dragged horizontally to unlock or perform an action. The view provides several customizable styling options, such as the size and color of the indicator and background, the text alignment, and whether the text fades or hides behind the indicator.
https://user-images.githubusercontent.com/20423069/232328779-f6ae204b-7ef6-4e96-93b0-8b7aa57e9617.mov
## Installation
You can install SlideButton using Swift Package Manager. To add SlideButton to your Xcode project, go to `File` > `Swift Packages` > `Add Package Dependency` and enter the URL `https://github.com/no-comment/SlideButton`.
## Usage
To use SlideButton, import the module `SlideButton` in your SwiftUI view.
```swift
import SwiftUI
import SlideButton
```Create a `SlideButton` by providing a title and a callback that will execute when the user successfully swipes the indicator.
```swift
SlideButton("Slide to Unlock") {
await unlockDevice()
}
.padding()
```You can customize the appearance of the slide button by providing a `Styling` instance. For example, you can change the size and color of the indicator, the alignment of the title text, and whether the text fades or hides behind the indicator.
```swift
let styling = SlideButton.Styling(
indicatorSize: 60,
indicatorSpacing: 5,
indicatorColor: .accentColor,
backgroundColor: .accentColor.opacity(0.3),
textColor: .secondary,
indicatorSystemName: "chevron.right",
indicatorDisabledSystemName: "xmark",
textAlignment: .center,
textFadesOpacity: true,
textHiddenBehindIndicator: true,
textShimmers: false
)SlideButton("Slide to Unlock", styling: styling) {
await unlockDevice()
}
.padding()
```## Documentation
SlideButton comes with documentation comments to help you understand how to use the package. You can access the documentation by option-clicking on any `SlideButton` or `Styling` instance in your code.