let alertController =UIAlertController(title:"系统提示",
message:"您确定要退出程序吗?", preferredStyle: .alert)
let cancelAction =UIAlertAction(title:"取消", style: .cancel, handler:nil)
let okAction =UIAlertAction(title:"好的", style: .default, handler: {
action in
print("点击了确定")
})
alertController.addAction(cancelAction)
alertController.addAction(okAction)
self.present(alertController, animated:true, completion: nil)
}
///1.点击不响应提示框
func mAlert(title:String,message:String) {
let alert = UIAlertView(title: title, message: message, delegate: nil, cancelButtonTitle: "确定")
alert.show()
}
///2.带确认的提示框
func OkAlert(title:String,message:String,vc: UIViewController ,sure: @escaping ()->Void) {
let alertController = UIAlertController(title: title, message: message, preferredStyle:.alert)
// 设置2个UIAlertAction
let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
let okAction = UIAlertAction(title: "确定", style: .default) { (UIAlertAction) in
sure()
}
// 添加
alertController.addAction(cancelAction)
alertController.addAction(okAction)
// 弹出
vc.present(alertController, animated: true, completion: nil)
}
///3.带输入框提示框
func InputAlert(title:String,message:String,placeholder:String,vc: UIViewController ,sure: @escaping (_ text:String)->Void) {
let alertController = UIAlertController(title: title, message:message, preferredStyle: UIAlertControllerStyle.alert)
alertController.addTextField { (textField:UITextField) in
textField.placeholder = placeholder
}
let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel, handler: nil)
let okAction = UIAlertAction(title: "好的", style: UIAlertActionStyle.default) { (UIAlertAction) in
let login = alertController.textFields![0]
sure(login.text!)
print("输入的是:\(login.text)")
}
alertController.addAction(cancelAction)
alertController.addAction(okAction)
// 弹出
vc.present(alertController, animated: true, completion: nil)
}
}
/**
使用示例:
1. WSAlert.API.mAlert(title: "提示", message: "看看")
2. // WSAlert.API.InputAlert(title: "提示", message: "输入打赏金额", placeholder: "不大于1000", vc: self){(text) in
// print("输入:\(text)")
// }
3. WSAlert.API.OkAlert(title: "提示", message: "是否分享",vc:self){[weakSelf = self] in
WSShareView.shareview.showInView(view: weakSelf.view, type: .GeneralShare, shareImageURL: "分享图片url" as AnyObject, shareContent: "分享内容", shareTitle: "分享标题", shareUrl: "分享链接")
WSShareView.shareview.isShareSuccess = {(backMsg) in
print("结果:\(backMsg)")
}
*/