AlertKit

Apple Music 和 AppStore 中的弹出窗口和反馈。包含 DoneHeartError 等。支持深色模式。我尝试尽可能地重现 Apple 的警告框。你可以在 AppStore 的反馈之后以及在 Apple Music 中将歌曲添加到你的资料库之后找到这些警告框。

Alert Kit v5

对于 UIKit 和 SwiftUI,调用此方法

AlertKitAPI.present(
    title: "Added to Library",
    icon: .done,
    style: .iOS17AppleMusic,
    haptic: .success
)

提供 2 种样式

public enum AlertViewStyle {

    case iOS16AppleMusic
    case iOS17AppleMusic
}

iOS 开发社区

导航

安装

可在 iOS 13+ 上使用。支持 iOS 和 visionOS。可与 UIKitSwiftUI 协同工作。

Swift Package Manager

在 Xcode 中,前往 Project -> 你的项目名称 -> Package Dependencies -> 点击加号。插入 URL

https://github.com/sparrowcode/AlertKit

或将其添加到你的 Package.swiftdependencies

dependencies: [
    .package(url: "https://github.com/sparrowcode/AlertKit", .upToNextMajor(from: "5.1.8"))
]

CocoaPods

这是一种过时的方法。我建议你使用 SPM。但是,我将在一段时间内继续支持 Cocoapods。

Cocoapods 安装

CocoaPods 是一个依赖管理器。有关使用和安装说明,请访问他们的网站。要使用 CocoaPods 进行集成,请在你的 Podfile 中指定它

pod 'SPAlert'

手动

如果你不喜欢使用任何依赖管理器,你可以手动集成。将 Sources/AlertKit 文件夹放入你的 Xcode 项目中。确保启用 Copy items if neededCreate groups

SwiftUI

你可以使用通过 AlertKitAPI 的基本方法或通过修饰符调用

let alertView = AlertAppleMusic17View(title: "Hello", subtitle: nil, icon: .done)

VStack {}
    .alert(isPresent: $alertPresented, view: alertView)

自定义

如果你需要自定义字体、图标、颜色或任何其他内容,请创建视图

let alertView = AlertAppleMusic17View(title: "Added to Library", subtitle: nil, icon: .done)

// change font
alertView.titleLabel.font = UIFont.systemFont(ofSize: 21)
// change color
alertView.titleLabel.textColor = .white

呈现 & 关闭

你可以通过视图手动呈现和关闭警告框。

let alertView = AlertAppleMusic17View(title: "Added to Library", subtitle: nil, icon: .done)

// present
alertView.present(on: self)
// and dismiss
alertView.dismiss()

用于关闭所有已呈现的警告框

AlertKitAPI.dismissAllAlerts()

正在使用的应用

如果你使用了 AlertKit,请通过 Pull Request 添加你的应用。