250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- SWIFT
- 개발자
- ipad
- 비전공자
- 프론트엔드
- hover
- javascript
- HTML
- php
- button
- CSS
- react
- IOS
- 비전공 개발자
- Animation
- html5
- keyframes
- 풀스택
- 애니메이션
- image
- 백엔드
- MAC
- xcode
- jQuery
- iOS 개발자
- effect
- 자바스크립트
- css3
- iPhone
- front-end
Archives
- Today
- Total
비전공자 개발일기
UP and Down Number Game in iOS APP 본문
728x90
SMALL
import UIKit
// 1안
class ViewController: UIViewController {
@IBOutlet weak var mainLabel: UILabel!
@IBOutlet weak var numLabel: UILabel!
var comChoice = Int.random(in: 1...10)
var myChoice = 1
override func viewDidLoad() {
super.viewDidLoad()
mainLabel.text = "아래 숫자들 중에서 선택"
numLabel.text = ""
}
@IBAction func btnPressed(_ sender: UIButton) {
guard let numString = sender.currentTitle else {
return
}
numLabel.text = numString
guard let num = Int(numString) else {return}
myChoice = num
}
@IBAction func selectBTNPressed(_ sender: UIButton) {
if(comChoice > myChoice) {
mainLabel.text = "👍"
} else if(comChoice < myChoice) {
mainLabel.text = "👎"
} else {
mainLabel.text = "👌"
}
}
@IBAction func resetBTNPressed(_ sender: UIButton) {
mainLabel.text = "아래 숫자들 중에서 선택"
numLabel.text = ""
comChoice = Int.random(in: 1...10)
}
}
// 2안
//class ViewController: UIViewController {
//
// @IBOutlet weak var mainLabel: UILabel!
// @IBOutlet weak var numLabel: UILabel!
//
// var comChoice = Int.random(in: 1...10)
//
// override func viewDidLoad() {
// super.viewDidLoad()
// mainLabel.text = "아래 숫자들 중에서 선택"
// numLabel.text = ""
// }
//
// @IBAction func btnPressed(_ sender: UIButton) {
// guard let numString = sender.currentTitle else {
// return
//
// }
// numLabel.text = numString
// }
//
// @IBAction func selectBTNPressed(_ sender: UIButton) {
// guard let myNumString = numLabel.text else {return}
// guard let myNum = Int(myNumString) else {return}
// if(comChoice > myNum) {
// mainLabel.text = "👍"
// } else if(comChoice < myNum) {
// mainLabel.text = "👎"
// } else {
// mainLabel.text = "👌"
// }
// }
//
// @IBAction func resetBTNPressed(_ sender: UIButton) {
// mainLabel.text = "아래 숫자들 중에서 선택"
// numLabel.text = ""
// comChoice = Int.random(in: 1...10)
// }
//
//}
728x90
LIST
'SWIFT' 카테고리의 다른 글
[SWIFT] Coding Test Practice Day 2 (0) | 2022.11.08 |
---|---|
[SWIFT] Coding Test Practice Day 1 (0) | 2022.11.08 |
UP and DOWN Number Game (0) | 2022.11.05 |
Rock Scissors Paper (0) | 2022.11.04 |
Dice Game + breakpoint Error (0) | 2022.11.04 |