1、StoryboardにLabelと”+”と”ー”のbuttonを配置する
2、下記の処理をViewController.swiftに書く
3、@IBOutletの部分をLabelと紐づける
4、@IBActionの部分をButtonと紐づける
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var countLabel: UILabel!
var count = 0
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func countupBotton(_ sender: AnyObject) {
if count == 10{
return
}
count = count + 1
countLabel.text = String(count)
}
@IBAction func countdownButton(_ sender: AnyObject) {
if count == 0{
return
}
count = count - 1
countLabel.text = String(count)
}
}