1.創建新項目
2.設計布局,main.storyboard中,在控件庫中
3.布局控件關聯控制器
4.設置事件或者顯示模式
5.編寫代碼:
import UIKit class ViewController: UIViewController { @IBAction func btn1(_ sender: UIButton) { label1.text="我的第一個程序" } @IBOutlet weak var label1: UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } @IBOutlet weak var hello: UILabel! override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
最后運行:
點擊按鈕改變label控件文字: