Apple developed the "swift simple buttons plus 1 count Getting Started"

    Open Xcode tools, project build Single View Application, select the Swift language, developed into the main interface, Main.storyboard under point left the project directory, you can interface the (first select the iOS development projects), added button and drag the label control, press live control guidelines mouse drag two controls in show the assisant editor to edit the page, automatically added @IBOutlet var outputlabel:! UILabel = UILabel () Note: = UILabel (later) wrote, 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
    }

}
View Code

button button pop-up box, connecting choose action, etc.

 

Guess you like

Origin www.cnblogs.com/shiningleo007/p/12444418.html