BDCustomAlertController
它做什么?
UIAlertAction
-
使用 actionWithTitle:image:style:handler 在 UIAlertAction 中显示 UIImage
-
通过调用 actionWithCustomContent:handler 使用您的布局(前缀或后缀)显示图像和文本
UIAlertController
-
计算后的着色色度
-
日期选择器作为内容视图控制器
-
将根据您的要求添加更多内容选项
例子
要运行示例项目,克隆仓库,然后首先从示例目录中运行 pod install
。
显示带文本和图像的 UIAlertAction
func displayAlertActionWithImage(){
let alert = UIAlertController(title: "yo!", message: "a message", preferredStyle: .alert)
let action = UIAlertAction(title: "Your Text", image: UIImage(named: "your_image_name"), style: .default) { (_) in
//some code to handle the action
}
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}
显示带有UIDatePicker的UIAlertController
func displayAlertWithDatePicker(){
let alert = UIAlertController(title: "yo!", message: "select a date messsage", preferredStyle: .alert)
alert.insertDatePicker { (datePicker) in
//config date picker as you like here
}
alert.addAction(UIAlertAction(title: "Done", style: .default, handler: { (_) in
guard let datePicker = alert.datePicker() else{
return
}
print("selected date is \(datePicker.date)")
}))
self.present(alert, animated: true, completion: nil)
}
安装
BDCustomAlertController 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod 'BDCustomAlertController'
作者
Benny Davidovitz
许可证
BDCustomAlertController 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。