[๐Ÿ“ iOS TIL] #17 ... 1st Team Project - Coffee Ordering App #1

TaeUkยท2024๋…„ 4์›” 1์ผ
0

๐ŸŽ iOS TIL

๋ชฉ๋ก ๋ณด๊ธฐ
16/18
post-thumbnail

ํŒ€ ํ”„๋กœ์ ํŠธ ์‹œ์ž‘!

๋ถ€ํŠธ์บ ํ”„๊ฐ€ ์‹œ์ž‘๋˜๊ณ , ์ฒ˜์Œ์œผ๋กœ ๊ฐœ์ธ๊ณผ์ œ๊ฐ€ ์•„๋‹Œ ํŒ€ ํ”„๋กœ์ ํŠธ๋ฅผ ์ ‘ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค!

์ฃผ์ œ๋Š” "์ปคํ”ผ ์ฃผ๋ฌธ ํ‚ค์˜ค์Šคํฌ"๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด๋‹ค!!!

ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๋„ ํ•„์ˆ˜ ๊ตฌํ˜„ ๊ธฐ๋Šฅ๊ณผ ์„ ํƒ ๊ตฌํ˜„ ๊ธฐ๋Šฅ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์œผ๋ฉฐ, ํ˜ผ์ž์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋นŒ๋“œํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ํŒŒํŠธ๋ฅผ ๋‚˜๋ˆ„์–ด ํŒ€์›๊ณผ ํ•จ๊ป˜ ์„ค๊ณ„ํ•˜๋Š” ํ”„๋กœ์ ํŠธ์ด๊ธฐ์— ๋งค์šฐ ๊ธฐ๋Œ€๋œ๋‹ค! ๐Ÿ™‰


ํ”„๋กœ์ ํŠธ ์š”๊ตฌ ์‚ฌํ•ญ

ํ•„์ˆ˜ ๊ตฌํ˜„ ๊ธฐ๋Šฅ

  • ๋ฉ”์ธ ํŽ˜์ด์ง€
  • ์ƒ๋‹จ ๋ฉ”๋‰ด ์นดํ…Œ๊ณ ๋ฆฌ ๋ฐ”
    • UIStackView , UICollectionView ๋“ฑ์„ ํ™œ์šฉ
  • ๋ฉ”๋‰ด ํ™”๋ฉด
    • UICollectionView ๋“ฑ์„ ํ™œ์šฉ
  • ์ฃผ๋ฌธ ๋‚ด์—ญ ํ™”๋ฉด
    • UITableView ๋“ฑ์„ ํ™œ์šฉํ•˜์—ฌ ํ™”๋ฉด์„ ๊ตฌ์„ฑ
  • ์ทจ์†Œํ•˜๊ธฐ / ๊ฒฐ์ œํ•˜๊ธฐ ๋ฒ„ํŠผ ํ™”๋ฉด

์„ ํƒ ๊ตฌํ˜„ ๊ธฐ๋Šฅ

  • ๋ถ€๊ฐ€ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
    • ex. ๋‹๋ณด๊ธฐ ์™€ ๊ฐ™์€ ๋ถ€๊ฐ€์ ์ธ ๊ธฐ๋Šฅ ๊ตฌํ˜„
    • ex. ์˜ค๋Š˜์˜ ์ œ์ผ ์ž˜ ํŒ”๋ฆฐ ๋ฉ”๋‰ด ๋ณด๊ธฐ
    • ex. ์ง์›ํ˜ธ์ถœ โ†’ alert์ฐฝ ๋„์šฐ๊ธฐ
  • ๋‹คํฌ ๋ชจ๋“œ ๊ตฌํ˜„
  • ํŽ˜์ด์ง• ๊ธฐ๋Šฅ

์•„์ง ์‹œ์ž‘๋„ ์•ˆํ–ˆ๋Š”๋ฐ... ๋จธ๋ฆฌ๊ฐ€ ์•„ํŒŒ์˜จ๋‹ค...... ๐Ÿ™ˆ


์‹œ์ž‘ํ•˜์ž ๋ง์ž ๐Ÿถ๊ฐ™์ด ๋ฉธ๋ง...

์šฐ์„  ํ•„์ˆ˜ ๊ตฌํ˜„ ๊ธฐ๋Šฅ๋ถ€ํ„ฐ ์„ค๊ณ„๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด, App์˜ UI๋ฅผ ๊ทธ๋ ค์•ผ ํ–ˆ๋‹ค.

์ด์ „์— ์กธ์—…์ž‘ํ’ˆ์„ ๋งˆ์น˜๊ณ  ์šฐ์—ฐํžˆ Figma๋ฅผ ์ ‘ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ๊ฐ€ ์žˆ์–ด์„œ, ์ด๋ฅผ ํ†ตํ•ด UI๋ฅผ ๋””์ž์ธํ•ด ๋ณด์•˜๋‹ค.

์ดํ›„, ์ด๋ฅผ ํ† ๋Œ€๋กœ Xcode์˜ StoryBoard์— UI๋ฅผ ๊ทธ๋ ธ๋‹ค!

์ด๋•Œ๊นŒ์ง€๋งŒ ํ•ด๋„ ์ˆœ์กฐ๋กœ์› ๋‹ค...

์ง€๋‚œ ๊ณผ์ œ๋ฅผ ํ•˜๋ฉฐ UITableView๋Š” ์–ด๋Š์ •๋„ ์ ์‘์ด ๋˜์—ˆ์ง€๋งŒ, UICollection์€ ์ฒ˜์Œ ์ ‘ํ•˜๋‹ค ๋ณด๋‹ˆ ๊ธฐ๋Šฅ ๊ตฌํ˜„์— ์–ด๋ ค์›€์ด ์žˆ์—ˆ๋‹ค.

ํ•œ์ฐธ๋™์•ˆ ์ฐพ์•„๋ณด๋‹ˆ UITableView์™€ ์œ ์‚ฌํ•œ ๋“ฏ ํ•˜์˜€์ง€๋งŒ, ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ•˜์ง€ ๋ชปํ•˜์˜€๋‹ค...

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var CoffeListCollection: UICollectionView!
    @IBOutlet weak var CoffeeListSelector: UISegmentedControl!
    
    
    let coffeeDataSet = [
        "์•„๋ฉ”๋ฆฌ์นด๋…ธ": "2500",
        "์นดํŽ˜๋ผ๋–ผ": "4000",
        "์—์Šคํ”„๋ ˆ์†Œ": "2000"
    ]
    
    let teaDataSet = [
        "์ผ€๋ชจ๋งˆ์ผํ‹ฐ": "4000",
        "์•„์ด์Šคํ‹ฐ": "3500",
        "๋ ˆ๋ชฌํ‹ฐ": "4000",
        "๊ทธ๋ฆฐํ‹ฐ": "3500"
    ]
    
    let cakeDataSet = [
        "๋ธ”๋ฃจ๋ฒ ๋ฆฌ์น˜์ฆˆ์ผ€์ต": "6000",
        "๋ฐ”์Šคํฌ ์น˜์ฆˆ์ผ€์ต": "5500",
        "๋‹น๊ทผ ์ผ€์ต": "6500"
    ]
    
    var currentDataSet: [String: String] = [:]
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        CoffeeListSelector.addTarget(self, action: #selector(segmentedControlValueChanged(_:)), for: .valueChanged)
        
        CoffeListCollection.isHidden = false
        
        currentDataSet = coffeeDataSet
    }
    
    
    @objc func segmentedControlValueChanged(_ sender: UISegmentedControl) {
        switch sender.selectedSegmentIndex {
        case 0:
            currentDataSet = coffeeDataSet
        case 1:
            currentDataSet = teaDataSet
        case 2:
            currentDataSet = cakeDataSet
        default:
            break
        }
        CoffeListCollection.reloadData()
    }
}

๊ทธ๋ž˜์„œ UISegmentedControl๋งŒ ์ผ๋‹จ ์ ์šฉ์‹œ์ผœ ๋ณด์•˜๋‹ค.

ํ•ด๋‹น ์„ ํƒ ์š”์†Œ๋Š” StoryBoard์—์„œ ์„ค์ •ํ•˜์˜€์œผ๋ฉฐ, ์„ ํƒ๋œ ๊ฐ’์ด 0 ~ 2์ธ์ง€๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ currentDataSet๋ผ๋Š” Dictionary ํƒ€์ž…์˜ ๋นˆ ๋ฐฐ์—ด์— ์•Œ๋งž๋Š” DataSet์œผ๋กœ ์ดˆ๊ธฐํ™”์‹œํ‚จ๋‹ค.

์ด๋•Œ, DataSet์€ ์ด 3 ์ข…๋ฅ˜์ด๋ฉฐ coffeeDataSet, teaDataSet, cakeDataSet์œผ๋กœ ์ƒํ’ˆ ์ •๋ณด์™€ ๊ฐ€๊ฒฉ์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋‹ค.

UICollectionView๋งŒ ํ•ด๊ฒฐ๋˜๋ฉด, ๊ฐ Cell์— ์ด๋ฏธ์ง€๋ฅผ ๋„ฃ์–ด๋ณด๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ•  ์˜ˆ์ •์ด๋‹ค!


์ผ๋‹จ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ...

์˜ค๋Š˜ ํ•˜๋ฃจ ์‹ค์งˆ์ ์ธ ์„ฑ๊ณผ๊ฐ€ ์—†๋‹คํ•ด๋„ UICollectionView์„ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ณ , ํ”„๋กœ์ ํŠธ๋ฅผ ์ „๋ฐ˜์ ์œผ๋กœ ์–ด๋–ป๊ฒŒ ์„ค๊ณ„ํ•˜๋ฉด ๋˜๊ฒ ๋‹ค๋Š” ์ฒญ์‚ฌ์ง„์ด ๋จธ๋ฆฌ์†์—์„œ ๊ทธ๋ ค์กŒ๋‹ค!!

๊ทธ๋‚˜๋งˆ ๋‹คํ–‰์ผ์ง€๋„..

๊ฐ€๋Šฅํ•˜๋ฉด ์˜ค๋Š˜ ์ค‘์œผ๋กœ UICollectionView์„ ๋งˆ๋ฌด๋ฆฌํ•˜๊ณ , UITableView๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ๋‹ค. ๐Ÿ˜…

2๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2024๋…„ 4์›” 2์ผ

์‘์•  ์ž˜ ๋ชฐ?๋ฃจ

1๊ฐœ์˜ ๋‹ต๊ธ€