是否曾经觉得需要自定义 iOS 提供的枯燥默认警告框 UIAlertController? BBAlert 允许您这样做,但不会失去 UIAlertController 的功能。 由于它是作为 UIAlertController 的类型别名构建的,因此它不会占用更多内存。 该软件包使用 Xcode 11.4.1 在 MacOS 10.15.4 上使用 Swift 5.2.2 编译器编译。
import UIKit
import BBAlert
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let actions: [String: UIAlertAction.Style] = [selectedActionText: .default, "Cancel": .cancel]
presentBBAlert(title: "Title", message: "This is a sample message", actions: actions, setup: { alert in
alert.titleFont = .boldSystemFont(ofSize: 20)
alert.messageFont = .systemFont(ofSize: 16)
alert.backgroundColor = Color.allCases[self.selectedBackgroundColorIndex].color
alert.textColor = Color.allCases[self.selectedTextColorIndex].color
}, actionHandler: { action in
if action.title == self.selectedActionText {
print("Selected \(self.selectedActionText)")
}
}) { _ in
print("Perform stuff after completion.")
}
}
}
动画 | 深色模式 | 浅色模式 |
![]() |
![]() |
![]() |
Swift 包管理器是一种自动分发 Swift 代码的工具,并已集成到 swift
编译器中。 它还处于早期开发阶段,但 BBAlert 确实支持在支持的平台上使用它。
设置好 Swift 包后,将 BBAlert 添加为依赖项就像将其添加到 Package.swift
的 dependencies
值一样简单。
dependencies: [
.package(url: "https://github.com/bibinjacobpulickal/BBAlert.git", .upToNextMajor(from: "1.0.0"))
]
克隆或下载项目。 在 Xcode 中打开 .xcodeproj
文件。 将目标更改为 iOSExample 并在设备或模拟器上运行。
BBAlert 在 MIT 许可证下发布。 有关详细信息,请参阅 LICENSE。