MDTAlert
MDTAlert是一个Swift框架,用于在iOS上显示弹窗。所有的弹窗都是使用约束创建的,因此它是响应式的。
要求
- iOS 9.0+
- Swift 5.0+
功能
- 使用约束的简单弹窗视觉
- 屏幕顶部和底部的弹窗或给定UIView的弹窗
- 带属性文本的弹窗
安装
CocoaPods
CocoaPods是一个用于Cocoa项目的依赖关系管理器。有关使用和安装说明,请访问他们的网站。要使用CocoaPods将MDTAlert集成到您的Xcode项目中,请在您的Podfile
中指定它。
pod 'MDTAlert'
使用方法
可以创建一个警报并保存其引用,或者只是展示它。
创建方法
MDTAlert.createAlert(text: String, position: AlertPosition = .top, dismissTime: TimeInterval = 3, parentView: UIView? = UIApplication.shared.keyWindow)
MDTAlert.createAlert(attributedText: NSAttributedString, position: AlertPosition = .top, dismissTime: TimeInterval = 3, parentView: UIView? = UIApplication.shared.keyWindow) -> MDTAlerting
展示方法
MDTAlert.showAlert(text: String, position: AlertPosition = .top, dismissTime: TimeInterval = 3, parentView: UIView? = UIApplication.shared.keyWindow, animated: Bool = true)
MDTAlert.showAlert(attributedText: NSAttributedString, position: AlertPosition = .top, dismissTime: TimeInterval = 3, parentView: UIView? = UIApplication.shared.keyWindow, animated: Bool = true) -> MDTAlerting
创建并显示带有属性的文本和背景颜色的警报
import MDTAlert
let attributes: [NSAttributedString.Key : Any]? = [
.font: UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor.white
]
let attributedText = NSAttributedString(string: "message", attributes: attributes)
let alert = MDTAlert.createAlert(attributedText: attributedText, position: alertPosition)
alert.backgroundColor = .red
alert.present(animated: true)
创建并显示带有文本、背景颜色和自定义样式的警报
import MDTAlert
let alert = MDTAlert.createAlert(text: "message", position: alertPosition)
alert.setStyle(textColor: .white, font: UIFont.systemFont(ofSize: 22), textAligment: .center)
alert.backgroundColor = .black
alert.present(animated: true)
展示带有属性的文本的警报
import MDTAlert
let attributes: [NSAttributedString.Key : Any]? = [
.font: UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor.green
]
let attributedText = NSAttributedString(string: "message", attributes: attributes)
MDTAlert.showAlert(attributedText: attributedText, position: alertPosition)
展示纯文本的警报
import MDTAlert
MDTAlert.showAlert(text: "message", position: alertPosition)
贡献
欢迎提交请求。对于重大更改,请先提交问题以讨论您想进行的更改。
请确保适当更新测试。