
import UIKitvar imageVIEw:UIImageVIEw!class VIEwController: UIVIEwController { overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() let button = UIbutton(frame: CGRect(x: 150,y: 250,wIDth: 50,height: 50)) button.backgroundcolor = UIcolor.black button.addTarget(self,action: #selector(VIEwController.alertVIEw),for: .touchUpInsIDe) self.vIEw.addSubvIEw(button) } @objc func alertVIEw() { //创建UIAlertController(警告窗口) let alert = UIAlertController(Title: "information",message: "sub Title",preferredStyle: .alert) //创建UIAlertController(动作表单) let alertB = UIAlertController(Title: "information",preferredStyle: .actionSheet) //创建UIAlertController的Action let OK = UIAlertAction(Title: "OK",style: .default) { (UIAlertAction) in print("you selected ok") } let Cancel = UIAlertAction(Title: "Cancel",style: .cancel) { (UIAlertAction) in print("you selected cancel") } //将Actiont加入到AlertController alert.addAction(OK) alert.addAction(Cancel) //以模态方式d出 self.present(alert,animated: true,completion: nil) }} 添加文本输入框 import UIKitvar imageVIEw:UIImageVIEw!class VIEwController: UIVIEwController { overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() self.presentedVIEwController?.dismiss(animated: false,completion: nil) } overrIDe func vIEwDIDAppear(_ animated: Bool) { super.vIEwDIDAppear(animated) //添加任意数量文本输入框 let alertController = UIAlertController(Title: "登陆",message: "输入账号密码",preferredStyle: .alert) alertController.addTextFIEld { (textFIEld:UITextFIEld) in textFIEld.placeholder = "用户"} alertController.addTextFIEld { (textFIEld:UITextFIEld) in textFIEld.placeholder = "密码" textFIEld.isSecureTextEntry = true } let Login = UIAlertAction(Title: "登陆",style: .default,handler: nil) let Quit = UIAlertAction(Title: "退出",style: .cancel,handler: nil) alertController.addAction(Login) alertController.addAction(Quit) //模态d出提示框 self.present(alertController,completion: nil) //移除提示框 self.presentedVIEwController?.dismiss(animated: false,completion: nil) }} 自动消失的提示框 import UIKitvar imageVIEw:UIImageVIEw!class VIEwController: UIVIEwController { overrIDe func vIEwDIDLoad() { } overrIDe func vIEwDIDAppear(_ animated: Bool) { super.vIEwDIDAppear(animated) let alert = UIAlertController(Title: "自动关闭",message: "3s",preferredStyle: .alert) self.present(alert,completion: nil) dispatchQueue.main.asyncAfter(deadline: dispatchTime.Now() + 3) { self.presentedVIEwController?.dismiss(animated: true,completion: nil) } }} 总结 以上是内存溢出为你收集整理的Swift - UIAlertController全部内容,希望文章能够帮你解决Swift - UIAlertController所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)