SwiftUI 软件包,提供可自定义的滑动按钮,可以滑动以解锁或执行操作
滑动按钮
SlideButton是一个SwiftUI软件包,它提供了一个可自定义的滑动按钮,可以滑动以解锁或执行操作。该按钮由背景色、标题、图标和指示器组成,可以水平拖动以解锁或执行操作。该视图提供了多个可自定义的样式选项,例如指示器和背景的大小和颜色、文本对齐方式以及文本是淡出还是隐藏在指示器后面。
安装
您可以使用 Swift Package Manager 安装 SlideButton。要将 SlideButton 添加到 Xcode 项目,请转到 > > 并输入 URL 。File
Swift Packages
Add Package Dependency
https://github.com/no-comment/SlideButton
用法
要使用 SlideButton,请在 SwiftUI 视图中导入模块。SlideButton
import SwiftUI
import SlideButton
Create a by providing a title and a callback that will execute when the user successfully swipes the indicator. Optionally, you can inform the SlideButton whether the callback was successful to play haptic feedback.SlideButton
SlideButton("Slide to Unlock") {
let success = await unlockDevice()
return success
}
.padding()
You can customize the appearance of the slide button by providing a 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.Styling
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
)
SlideButton("Slide to Unlock", styling: styling) {
let success = await unlockDevice()
return success
}
.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 or instance in your code.SlideButton
Styling