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控件文字: