CustomAlertView
使用 CustomAlertView,您可以创建一个简单的自定义警报,而不是使用苹果提供的默认警报,因为默认警报并不总是适合您的应用程序风格。
功能
-
适用于 UIKit 和 SwiftUI
-
添加图标
-
个性化标题、消息和两个按钮
-
可以隐藏标题、消息和取消按钮
-
更改警报位置 (.center 或 .bottom)
-
更改同意按钮的圆角
-
更改同意按钮颜色
-
更改视图背景颜色
最新
- 可以更改整个 AlertView 的圆角半径
- 在 .bottom 位置时添加从底部开始的动画
示例
位置和没有标题 | 半径和没有消息 | 图标和颜色 | 一个按钮 |
---|---|---|---|
安装
Swift 包管理器
要使用苹果的 Swift 包管理器 进行集成,请将以下内容添加到您的 Package.swift
dependencies: [
.package(url: "https://github.com/jadebowl/CustomAlertView.git", from: "1.0.0")
]
或者导航到您的 Xcode 项目,选择 Swift Packages
并点击 +
图标以搜索 CustomAlert
。
手动
如果您不想使用上述任何依赖管理器,可以将 CustomAlert 手动集成到项目中。只需将 Sources
目录拖放到您的 Xcode 项目。
用法
创建一个警报
import CustomAlert
var alert = AlertView()
自定义 UI 并添加淡入淡出过渡效果
alert.setupContents(delegate: self,
accentColor: .systemBlue,
backgroundColor: .systemBackground,
icon: UIImage(systemName: "hand.wave"),
title: "I am a title",
message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
agreeTitle: "Go to Settings",
cancelTitle: "Cancel",
position: .bottom(animated: true))
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)
}
}
贡献
非常欢迎贡献 🙌