使用 AlertViewCustom,您可以创建自定义的 UIAlertView,而不是使用 Apple 默认的,因为它并不总是符合您的应用程序风格。
底部 & 无标题 | 字体自定义 | 图标 & 颜色 | 单个按钮 |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
轮廓按钮 | |||
![]() |
要使用 Apple 的 Swift Package Manager 进行集成,请将以下内容作为依赖项添加到您的 Package.swift
中
dependencies: [
.package(url: "https://github.com/jadebowl/AlertViewCustom.git", from: "4.0.0")
]
或者,导航到您的 Xcode 项目,选择 Swift Packages
,然后单击 +
图标以搜索 AlertViewCustom
。
AlertViewCustom 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中
pod 'AlertViewCustom'
如果您不想使用上述任何依赖管理工具,您可以手动将 AlertViewCustom 集成到您的项目中。只需将 Sources
文件夹拖到您的 Xcode 项目中即可。
创建一个 Alert
import AlertViewCustom
var alert = AlertView()
自定义 UI 并添加淡入淡出过渡效果
let agreeButton = AgreeButton(title: "Go to Settings")
let alertSettings = AlertSettings(accentColor: .systemBlue,
backgroundColor: .systemBackground,
icon: UIImage(systemName: "hand.wave"),
title: "I am a title",
message: "Lorem ipsum dolor sit amet, consectetuadipiscing elit, sed do eiusmod tempor incididunt ulabore et dolore magna aliqua.",
agreeButton: agreeButton,
cancelTitle: "Cancel",
position: .bottom(animated: true))
alert.setupContents(delegate: self, settings: alertSettings)
alert.fadeIn(duration: 0.3)
管理操作
extension Controller: AlertViewDelegate {
func agreeAction() {
// MARK: - Example: Go to Settings
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { return }
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
print("Settings opened: \(success)")
})
}
}
func cancelAction() {
alert.removeFromSuperView(duration: 0.3)
}
}
非常欢迎贡献 🙌