Yagom.net > Cources > iOS > ios-starter-uikit
야곰닷넷의 '왕초보를 위한 iOS 앱개발' 코스 수강에 대한 결과물입니다.
- 개발 환경 : MacBook Pro (13-inch, M1, 2020), Monterey
- XCode : Version 13.1 (13A1030d)
- 시뮬레이터 : iPhone 11
- 전체 ViewController 코드
import UIKit class ViewController: UIViewController { var randomValue: Int = 0 var tryCount: Int = 0 @IBOutlet weak var slider: UISlider! @IBOutlet weak var tryCountLabel: UILabel! @IBOutlet weak var sliderValueLabel: UILabel! @IBOutlet weak var minimumValueLabel: UILabel! @IBOutlet weak var maximumValueLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() slider.setThumbImage(#imageLiteral(resourceName: "slider_thumb"), for: .normal) resetAction() } @IBAction func sliderValueChanged(_ sender: UISlider){ print(sender.value) let integerValue: Int = Int(sender.value) sliderValueLabel.text = String(integerValue) } @IBAction func touchUpHitButton(_ sender: UIButton){ print("touchUpHitButton") let hitValue: Int = Int(slider.value) slider.value = Float(hitValue) tryCount += 1 tryCountLabel.text = "\(tryCount) / 5" if randomValue == hitValue{ showAlert(message: "YOU HIT!!") resetAction() }else if tryCount >= 5{ showAlert(message: "YOU LOSE..") resetAction() }else if randomValue > hitValue{ slider.minimumValue = Float(hitValue) minimumValueLabel.text = String(hitValue) }else{ slider.maximumValue = Float(hitValue) maximumValueLabel.text = String(hitValue) } } @IBAction func touchuUpResetButton(_ sender: UIButton){ print("touchUpResetButton") resetAction() } func resetAction(){ print("reset") randomValue = Int.random(in: 0...30) tryCount = 0 tryCountLabel.text = "\(tryCount) / 5" slider.value = 15 slider.minimumValue = 0 slider.maximumValue = 30 sliderValueLabel.text = "15" minimumValueLabel.text = "0" maximumValueLabel.text = "30" } func showAlert(message: String){ let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert) let okAction = UIAlertAction(title: "OK", style: .default) { (action) in self.resetAction() } alert.addAction(okAction) present(alert, animated: true, completion: nil) } }
https://yagom.net/courses/ios-starter-uikit/
'iOS 앱 프로그래밍 > iOS 프로젝트' 카테고리의 다른 글
[iOS Dev] To-Do Management Application Using Core Data (0) | 2021.11.16 |
---|---|
[Clone Project] the Official iOS Clock Alarm Application (0) | 2021.11.16 |