iOS(6) 有关于alertcontroller的一些事情
iOS(6) 有关于alertcontroller的一些事情
所有的alert都要有的
present(alert, animated: true, completion: nil)
actionsheet
@IBAction func actionSheet(_ sender: Any) {
let alert = UIAlertController(title: "action sheet", message: "this is an ation sheet", preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "RED", style: .default, handler: { (action) in
print("ok clicked")
self.view.backgroundColor = UIColor.red
}))
alert.addAction(UIAlertAction(title: "Green", style: .destructive, handler: { (action) in
print("destructive clicked")
self.view.backgroundColor = UIColor.green
}))
alert.addAction(UIAlertAction(title: "White", style: .cancel, handler: { (action) in
print("cancel clicked")
self.view.backgroundColor = UIColor.white
}))
present(alert, animated: true, completion: nil)
}
最厚的效果
alert对话框中弹出登陆表单
@IBAction func login(_ sender: Any) {
let alert = UIAlertController(title: "Login", message: "Please input your personal information", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Login", style: .default, handler: { (action) in
if let userNameTextField = alert.textFields?.first, let passWordTextField = alert.textFields?.last {
print("username:\(userNameTextField.text!) password:\(passWordTextField.text!)")
}
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) in
}))
alert.addTextField { (textField) in
textField.placeholder = "your user name?"
}
alert.addTextField { (textField) in
textField.placeholder = "your password?"
textField.isSecureTextEntry = true
}
present(alert, animated: true, completion: nil)
}