打开Xcode工具,project建立Single View Application,选择Swift语言,进入到主要开发界面,点左边项目目录下的Main.storyboard,就可以界面了(首先选择iOS开发项目),拖拉加入button和label控件,按住control在show the assisant editor编辑页面下鼠标指引这两个控件拖拉,自动添加 @IBOutlet var outputlabel:UILabel!=UILabel() 注:=UILabel()后写, currentcount=currentcount+1, outputlabel.text="the button has been Clicked (currentcount) number of times", outputlabel.textColor=UIColor.blue
import UIKit class ViewController: UIViewController { @IBOutlet var outputlabel: UILabel!=UILabel() var currentcount:integer_t=0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func ButtonLable(_ sender: UIButton) { currentcount=currentcount+1 outputlabel.text="the button has been Clicked (currentcount) number of times" outputlabel.textColor=UIColor.blue } }
button按钮弹出框,connecting选择action等