一
選擇 Single View Application模版swift語言 創建一個工程
二
在storyboard里拖兩個 Button 按鈕 和一個 label
屏幕快照 2016-11-27 下午7.33.14.png
三
將label 從storyboard拖到 實現文件 添加為輸出接口
將兩個 Button 拖到實現文件 添加 動作
使用 UIControlStatus.Normal 方法獲取按鈕標題
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var statusLabel: UILabel!
@IBAction func buttonPressed(_ sender: UIButton) {
let title=sender.title(for: .normal)!
let plainText="\(title) button pressed"
statusLabel.text=plainText
}
}```
###四
實現點擊不同的按鈕,文本框出現不同的字
](http://upload-images.jianshu.io/upload_images/2508221-929cf846d5107e52.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)