LoadingButton:SwiftUI下的加载动画按钮,支持自定义样式和加载状态控制





项目名称:LoadingButton

简介

LoadingButton是一个开源的SwiftUI库,提供了一个简单而强大的加载动画按钮组件。它允许开发者在SwiftUI应用中轻松添加带有加载动画的按钮,并支持完全自定义按钮样式。

预览

Preview

开始使用

要求

  • Xcode 11+

  • SwiftUI

  • iOS 14+

  • macOS 10.15+

安装

通过Swift Package Manager(SPM)安装:

.package(url: "https://github.com/Changemin/LoadingButton", from: "1.1.2")

使用方法

LoadingButton(action: { }, isLoading: <Binding>Bool, style: LoadingButtonStyle) {
    // View on the button
    // style is optional parameter
}

自定义样式

LoadingButtonStyle(width: CGFloat, 
                   height: CGFloat,
                   cornerRadius: CGFloat,
                   backgroundColor: Color,
                   loadingColor: Color,
                   strokeWidth: CGFloat,
                   strokeColor: Color)

示例代码

简单示例

import SwiftUI
import LoadingButton

struct ContentView: View {
    @State var isLoading: Bool = false

    var body: some View {
        LoadingButton(action: {
            // Your Action here
        }, isLoading: $isLoading) {
            Text("LoadingButton").foregroundColor(Color.white)
        }
    }
}

完全自定义样式示例

import SwiftUI
import LoadingButton

struct ContentView: View {
    @State var isLoading: Bool = false
    var style = LoadingButtonStyle(width: 312,
                              height: 54,
                              cornerRadius: 27,
                              backgroundColor: .orange,
                              loadingColor: Color.orange.opacity(0.5),
                              strokeWidth: 5,
                              strokeColor: .gray)

    var body: some View {
        LoadingButton(action: {
            // Your Action here
        }, isLoading: $isLoading, style: style) {
            Text("Styled LoadingButton").foregroundColor(Color.white)
        }
    }
}

 

许可证

LoadingButton在MIT许可下可用。更多信息请查看LICENSE文件。

或许喜欢

SwiftfulLoadingIndicators:SwiftUI加载动画库,20+动画,高度可定制

SwiftfulLoadingIndicators是一个轻量级的SwiftUI加载动画库,提供20多种动画效果,支持高度自定义颜色、大小和速度,适用于iOS、macOS等平台.

最近更新 2025-01-07

AnimateText:SwiftUI文本动画库支持iOS/macOS

AnimateText是一个用于SwiftUI的文本动画库,支持iOS和macOS平台,允许开发者创建自定义动画效果,增加应用的动态交互体验。

最近更新 2024-12-09

LightDarkMode-ToggleStyle:SwiftUI自定义开关样式与动画

LightDarkMode-ToggleStyle是一个SwiftUI开源项目,提供自定义开关样式和流畅动画效果,适用于iOS应用的UI设计和交互优化。

最近更新 2025-01-07

热榜

Made with in Shangrao,China By 老雷

Copyright © devler.cn 1987 - Present

赣ICP备19009883号-1