当アカウントへ訪れていただき、誠にありがとうございます。第23回アプリ教室では、カウンターアプリを作ります。自分のペースで勉強したい、勉強前に予習したい、内容を復習したい場合、ご利用ください。
Meetup http://www.meetup.com/ios-dev-in-namba/
http://learning-ios-dev.esy.es/
株式会社ジーライブ http://geelive-inc.com
Xcode 9.4 / Swift 4.1
0-1. Xcodeを起動。
0-2. "Create a new Xcode project"を選択。
0-3. "Single View Application"を選択して"Next"をクリック。
0-4. "Product name"を適当に入力して"Next"をクリック。
0-5. プロジェクトの場所を指定して"Create"をクリック。
1-1. UIButton を storyboad に追加(プラスボタン、マイナスボタン)
1-2. UILabel を storyboad に追加(数値を表示する為のラベル)
2-1. UIButton を "ViewController.swift" に紐付ける(connection を actionにする)
★ controlを押しながらドラッグ
2-2. UILabel を "ViewController.swift" に紐付ける(connection を Outlet にする)
★ controlを押しながらドラッグ
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var num: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func plus(_ sender: UIButton) {
let iNum: Int = Int(num.text!)!
let iNumPlus: Int = iNum + 1
num.text = "\(iNumPlus)"
}
@IBAction func minus(_ sender: UIButton) {
let iNum: Int = Int(num.text!)!
let iNumMinus: Int = iNum - 1
num.text = "\(iNumMinus)"
}
}
4-1. 数値を0に戻すリセットボタンを追加してみよう