iOS(Swift 語言)創(chuàng)建一個簡單的計數(shù)器應(yīng)用




一、iOS(Swift 語言)
假設(shè)創(chuàng)建一個簡單的計數(shù)器應(yīng)用,界面上有一個標(biāo)簽顯示當(dāng)前計數(shù),一個按鈕用于增加計數(shù)。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var countLabel: UILabel!
var count = 0
@IBAction func incrementButtonTapped(_ sender: Any) {
count += 1
countLabel.text = "Count: \(count)"
}
override func viewDidLoad() {
super.viewDidLoad()
countLabel.text = "Count: \(count)"
}
}
假設(shè)創(chuàng)建一個簡單的計數(shù)器應(yīng)用,界面上有一個標(biāo)簽顯示當(dāng)前計數(shù),一個按鈕用于增加計數(shù)。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var countLabel: UILabel!
var count = 0
@IBAction func incrementButtonTapped(_ sender: Any) {
count += 1
countLabel.text = "Count: \(count)"
}
override func viewDidLoad() {
super.viewDidLoad()
countLabel.text = "Count: \(count)"
}
}