iOS(Swift 語言)創(chuàng)建一個(gè)簡單的計(jì)數(shù)器應(yīng)用
二次開發(fā) admin 發(fā)布時(shí)間:2024-09-25 21:02:01 瀏覽: 次
一、iOS(Swift 語言)
假設(shè)創(chuàng)建一個(gè)簡單的計(jì)數(shù)器應(yīng)用,界面上有一個(gè)標(biāo)簽顯示當(dāng)前計(jì)數(shù),一個(gè)按鈕用于增加計(jì)數(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)建一個(gè)簡單的計(jì)數(shù)器應(yīng)用,界面上有一個(gè)標(biāo)簽顯示當(dāng)前計(jì)數(shù),一個(gè)按鈕用于增加計(jì)數(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)"
}
}