CustomAlertKit

Version License Platform SPM

安装

CustomAlertKit 支持 Swift Package ManagerCocoaPods

Swift Package Manager

要使用 Swift Package Manager 安装 CustomAlertKit,您可以按照 Apple 发布的 教程,使用仓库的 URL。

  1. 在 Xcode 中,选择 “File” → “Add Packages Dependencies”
  2. 输入 https://github.com/bence-t0th/CustomAlertKit.git

CocoaPods

将 pod 添加到您的 Podfile

pod 'CustomAlertKit'

然后运行

pod install

将 cocoapod 安装到您的项目后,使用以下命令导入 CustomAlertKit:

import CustomAlertKit

用法

底部表单 (Bottomsheet)

Bottomsheet

@State var bottomsheetVisible = false

var body: some View {
    ...
    }
    .bottomSheet(visible: $bottomsheetVisible, background: .blur(.regular), contentBackgroundColor: .white) {
        Text("This is a bottomsheet with blurred background")
            .frame(height: 250)
    }
}

Snackbar

Snackbar

@State var snackbarVisible = false

var body: some View {
    ...
    }
    .snackbar(visible: $snackbarVisible) {
        Text("This is a snackbar")
            .padding(16)
            .background(.green)
            .clipShape(Capsule())
    }
}

Alert (警报框)

Alert

@State var alertVisible = false

var body: some View {
    ...
    }
    .alert(visible: $alertVisible, background: .color(.black.opacity(0.4))) {
        VStack {
            Text("This is an alert with opaque background")
            Button(action: {
                withAnimation {
                    alertVisible.toggle()
                }
            }, label: {
                Text("Close")
            })
        }
        .padding(32)
        .background(.red)
    }
}

要求

CustomAlertKit 要求 iOS 15 部署目标,并且仅与 SwiftUI 兼容。

作者

Bence Tóth

许可证

CustomAlertKit 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。