iOS/Toy project

[iOS : Toy Project] Symbol Roller

yevdev 2022. 5. 12. 19:44

๐Ÿ“Œ์ฒซ๋ฒˆ์งธ ํ”„๋กœ์ ํŠธ

๋ฒ„ํŠผ์„ ํด๋ฆญํ•  ๋•Œ ๋งˆ๋‹ค ๋žœ๋ค์œผ๋กœ ๋‚ ์”จ(=Symbol)์ด ๋ฐ”๋€Œ๋Š” ์•ฑ์„ ๋งŒ๋“ค์–ด๋ณด์ž

 

 

 

1๏ธโƒฃ ์‚ฌ์ „์— ํ•„์š”ํ•œ ๋‹ค์šด๋กœ๋“œ : SF Symbols

SF Symbols

 

 

2๏ธโƒฃ ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ

- Stack View ์•ˆ์— Image View -> Label -> Button

 

 

 

3๏ธโƒฃ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ฝ”๋“œ

//
//  SymbolRollerViewController.swift
//  SymbolRoller
//
//  Created by ์˜ค์˜ˆ์ง„ on 2022/05/11.
//

import UIKit

// UIViewController = Page๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ํ•˜๋‚˜์˜ ๋‹จ์œ„
// UIViewController๋ฅผ ์ƒ์†๋ฐ›์€ SymbolRollerViewController
class SymbolRollerViewController: UIViewController {
    
    let symbols: [String] = ["sun.min", "moon", "cloud", "wind", "snowflake"]

    // @IBOutlet : Interface builder์— ์žˆ๋Š” UI ์ปดํฌ๋„ŒํŠธ์™€ ์—ฐ๊ฒฐ์„ ํ•˜๊ฒ ๋‹ค.
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var button: UIButton!
    
    func reload() {
        // TO_DO
        // - ์‹ฌ๋ณผ์—์„œ, ํ•˜๋‚˜๋ฅผ ์ž„์˜๋กœ ์ถ”์ถœํ•ด์„œ
        // - ์ด๋ฏธ์ง€์™€ ํ…์ŠคํŠธ ์„ค์ •์„ ํ•œ๋‹ค.
        let symbol = symbols.randomElement()!
        imageView.image = UIImage(systemName: symbol)
        label.text = symbol
    }
    
    // app ์‹คํ–‰ ์‹œ, viewDidLoad()๋ฅผ ๊ฑฐ์ณ์„œ ๋œฌ๋‹ค.
    override func viewDidLoad() {
        super.viewDidLoad()
        reload()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
    }
    
    // @IBAction : ํด๋ฆญ์ด ๋์„ ๋•Œ, ์–ด๋–ค ๊ฒƒ์„ ์ˆ˜ํ–‰ํ•˜๊ฒ ๋‹ค.
    @IBAction func buttonTapped(_ sender: Any) {
        reload()
    }
    
}

- View Controller : ํŽ˜์ด์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ์ฒด

- ํ™”๋ฉด์— ๋‚˜ํƒ€๋‚˜๋Š” View Controller๊ฐ€ ๊ฐ์ฒด๊ฐ€ ํ™”๋ฉด์— ๋ณด์ด๊ธฐ ๊นŒ์ง€ : viewDidLoad -> viewWillAppear -> viewDidAppear

 

- DRY : Do not Repeat Yourself (์ค‘๋ณต๋œ ์ฝ”๋“œ ์ฐธ์ง€ ์•Š๊ธฐ) == ํ•จ์ˆ˜๋กœ ๋งŒ๋“ค๊ธฐ

-> ์ด๋ฅผ ์œ„ํ•ด reload() ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค.

 

 

 

4๏ธโƒฃ ์ง€๊ธˆ๊นŒ์ง€ ๊ตฌํ˜„ํ•œ ํ™”๋ฉด

- ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด Image View์™€ Label์ด ๋ฐ”๋€Œ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Œ.

 

 

 

5๏ธโƒฃ ์ƒ‰์„ ์ž…ํ˜€ ๊พธ๋ฏธ๊ธฐ

 

1. Label Custom

 

2. Button Custom

- Image ํ•ญ๋ชฉ์— arrow.3.~ ์„ ๋„ฃ๊ณ  padding ํ•ญ๋ชฉ์„ 10์œผ๋กœ ๋งž์ถ”๋ฉด ํ…์ŠคํŠธ์™€ ์–ด๋Š์ •๋„ ๋–จ์–ด์ง„ ์ด๋ฏธ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚˜๊ฒŒ ๋œ๋‹ค.

 

 // app ์‹คํ–‰ ์‹œ, viewDidLoad()๋ฅผ ๊ฑฐ์ณ์„œ ๋œฌ๋‹ค.
    override func viewDidLoad() {
        super.viewDidLoad()
        reload()
        
        // ๋ฒ„ํŠผ์˜ tintColor ๋ฐ”๊พธ๊ธฐ
        button.tintColor = UIColor.systemPink
    }

- ์œ„์™€ ๊ฐ™์ด viewDidLoad() ํ•จ์ˆ˜์— ๋ฒ„ํŠผ์˜ tintColor์„ ๋ฐ”๊พธ๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ : button.tintColor = UIColor.systemPink

 

 

 

6๏ธโƒฃ ์™„์„ฑ๋œ ์•ฑ

 

 

 

 

 


Reference

ํŒจ์ŠคํŠธ์บ ํผ์Šค ์˜จ๋ผ์ธ ๊ฐ•์˜

'iOS > Toy project' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[iOS : Toy Project] Apple Framework List (2)  (0) 2022.05.28
[iOS : Toy Project] Apple Framework List (1)  (0) 2022.05.28
[iOS: Toy Project] Chat List  (0) 2022.05.23
[iOS : Toy Project] Stock Rank  (0) 2022.05.21
[iOS : Toy Project] Simple Weather  (0) 2022.05.17