Swift 学习笔记(三)
2019-01-21
在iOS上构建了两个基本按钮
ViewController.swift<\code>
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var txtName: UITextField!//文本框
@IBOutlet weak var tryBt: UIButton!//try 按钮
@IBAction func touchBt(_ sender: Any) {
/*UIAlertView 在iOS9之后不推荐使用
let alertView = UIAlertView()
alertView.title = "提示标题"
alertView.message = "提示信息 输入框: \(txtName.text!)"
alertView.addButton(withTitle: "好的")
alertView.show()
*/
let alertView = UIAlertController.init(title: "提示标题", message: "提示信息 输入框: \(txtName.text!)", preferredStyle: .alert)
let okButton = UIAlertAction(title: "好的", style: .default, handler: {
ACTION in
print("点击了 好的 按钮")
})
let cancelButton = UIAlertAction(title: "取消", style: .default, handler: nil)
alertView.addAction(okButton)
alertView.addAction(cancelButton)
self.present(alertView, animated: true, completion: nil)
}
@IBOutlet weak var try22: UIButton!//try2 按钮
@IBAction func try2(_ sender: Any) {
let alert = UIAlertController(title: "标题", message: "内容", preferredStyle: .alert)
let action = UIAlertAction(title: "标题2", style: .default){
(UIAlertAction) in
print("6666666")
}
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
参考资料 : http://www.hangge.com/blog/cache/detail_651.html 参考资料 : https://medium.com/@jacobhuang/swift-建立警告視窗-uialertcontroller-uialertaction-18c80a001649