HYAlertController 是一个极简的警告控制器,包含多种使用场景。它的语法与 Apple 的 UIAlertController
相同,因此您可以在自己的应用程序中轻松使用它。
下载并将 /HYAlertController
文件夹拖放到您的项目中。
用法与 UIAlertController
非常相似。《HYAlertController》有三种样式:警告、表单和共享。
警告样式:用此样式,您可以将显示内容居中,作为对话框的提示用户操作;
表单样式:用此样式,您可以将显示内容显示在屏幕底部,以下将弹出对话框供用户选择;
共享样式:类似于 表单样式,区别在于此样式可用于共享功能,您可以快速完成主流共享样式的创建。
//Work with Swift 3
let alertVC: HYAlertController = HYAlertController (title: "Title", message: "Here you can describe the details of its title, and you can write here what you want to express.", style: .alert)
let oneAction: HYAlertAction = HYAlertAction (title: "One Action", style: .normal, handler: { (action) in
print(action.title)
})
let twoAction: HYAlertAction = HYAlertAction (title: "Two Action", style: .normal, handler: { (action) in
print(action.title)
})
let threeAction: HYAlertAction = HYAlertAction (title: "Three Action", style: .destructive, handler: { (action) in
print(action.title)
})
let cancelAction: HYAlertAction = HYAlertAction (title: "Cancel Action", style: .cancel, handler: { (action) in
print(action.title)
})
alertVC.addAction(action: oneAction)
alertVC.addAction(action: twoAction)
alertVC.addAction(action: threeAction)
alertVC.addAction(action: cancelAction)
self.present(alertVC, animated: true, completion: nil)
//Work with Swift 3
let alertVC: HYAlertController = HYAlertController (title: "Title", message: "Here you can describe the details of its title, and you can write here what you want to express.", style: .actionSheet)
let oneAction: HYAlertAction = HYAlertAction (title: "One Action", style: .normal, handler: { (action) in
print(action.title)
})
let twoAction: HYAlertAction = HYAlertAction (title: "Two Action", style: .normal, handler: { (action) in
print(action.title)
})
let threeAction: HYAlertAction = HYAlertAction (title: "Three Action", style: .destructive, handler: { (action) in
print(action.title)
})
let cancelAction: HYAlertAction = HYAlertAction (title: "Cancel Action", style: .cancel, handler: { (action) in
print(action.title)
})
alertVC.addAction(action: oneAction)
alertVC.addAction(action: twoAction)
alertVC.addAction(action: threeAction)
alertVC.addAction(action: cancelAction)
self.present(alertVC, animated: true, completion: nil)
//Work with Swift 3
let alertVC: HYAlertController = HYAlertController (title: nil, message: nil, style: .shareSheet)
let oneAction: HYAlertAction = HYAlertAction (title: "Facebook", image: UIImage (named: "facebook")!, style: .normal, handler: {
(action) in
print(action.title)
})
let twoAction: HYAlertAction = HYAlertAction (title: "Twitter", image: UIImage (named: "twitter")!, style: .normal, handler: {
(action) in
print(action.title)
})
let threeAction: HYAlertAction = HYAlertAction (title: "Snapchat", image: UIImage (named: "snapchat")!, style: .normal, handler: {
(action) in
print(action.title)
})
let fourAction: HYAlertAction = HYAlertAction (title: "Instagram", image: UIImage (named: "instagram")!, style: .normal, handler: {
(action) in
print(action.title)
})
let fiveAction: HYAlertAction = HYAlertAction (title: "Pinterest", image: UIImage (named: "pinterest")!, style: .normal, handler: {
(action) in
print(action.title)
})
let sixAction: HYAlertAction = HYAlertAction (title: "Line", image: UIImage (named: "line")!, style: .normal, handler: {
(action) in
print(action.title)
})
alertVC.addShareActions(actions: [oneAction, twoAction, threeAction, fourAction, fiveAction, sixAction])
self.present(alertVC, animated: true, completion: nil)
有关更多用法场景,请参阅《HYAlertControllerDemo》以获取详细信息。
《HYAlertController》是用 Swift 3 开发的,因此您的 Swift 版本必须是 Swift 3。
HYAlertController
不提供外部定制,这与开发者想法相关。如果想做一些基本更改,请下载项目源代码,并修改HY_Constants.swift
文件,其中包含一些基本设置常量,对其进行修改。
修改后,可以使用上述手动安装方法将其集成到您的项目中。
HYAlertController 在MIT 许可下可用。有关更多信息,请参阅LICENSE文件。