iOS/Toy project

[iOS : Toy Project] Simple Weather

yevdev 2022. 5. 17. 15:41

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

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

Stack View ์†์— ๋˜ ๋‹ค๋ฅธ Stack View!

 

 

 

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

- Vertical Stack View ์†์— label, Image view, label, Horizontal Stack View (์ด ์†์— ๋˜ ๋ณตํ•ฉ์ ์ธ View), Button

 

 

2๏ธโƒฃ View Controller ์ด๋ฆ„ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ฐ”๊พธ๊ธฐ

- ๊ธฐ์กด view controller ํŒŒ์ผ ์ง€์šฐ๊ณ , file > Cocoa Touch Class > "WeatherViewController" ์ด๋ฆ„์˜ View Controller ๋งŒ๋“ค๊ธฐ

Custom Class, Storyboard ID ์„ค์ •

 

- Storyboard ID? View Controller์„ Storyboard์—์„œ ์ฐพ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ID

 

 

3๏ธโƒฃ ํ™”๋ฉด์„ค์ • (๋ ˆ์ด์•„์›ƒ ์„ค์ •)

Background: System Teal Color
Render Mode : Multicolor ๋กœ ์„ค์ •ํ•˜๋ฉด sun.max.fill ์˜ ๊ทธ๋ฆผ์ผ ๊ฒฝ์šฐ ๋…ธ๋ž€์ƒ‰์œผ๋กœ ์ž๋™ ์„ค์ •๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Œ
sun.max.fill์„ controlํ‚ค๋กœ ๋Œ๊ณ  ์™€์„œ height์„ ํ™•์ธํ•œ ํ›„, 180์œผ๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด ํฌ๊ธฐ๊ฐ€ ์ปค์ง!
๊ทธ๋ฆฌ๊ณ , Content Mode: Aspect Fit ์ด ์ž˜ ์„ค์ •๋˜์—ˆ๋Š”์ง€ ํ™•์ธ! (๋น„์œจ ์œ ์ง€๋ฅผ ํ•˜๋ฉฐ ํ™•์žฅ์„ ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•จ)
Stack Viewd์˜ item๋“ค ๊ฐ„์˜ ๊ฐ„๊ฒฉ์กฐ์ ˆ์€ Spacing ์—์„œ!

 

 

Stack View์—์„œ๋Š” Button(๊ทธ ์™ธ ๋‹ค๋ฅธ ์•„์ดํ…œ๋„)์ด ์–‘์˜†์œผ๋กœ Fill๋˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€์ƒ์˜ View๋ฅผ ๋งŒ๋“ค๊ณ  ๊ทธ ์•ˆ์— Button์„ ๋„ฃ์–ด ์–‘์˜†์— Padding์„ ์ค˜์•ผ ํ•œ๋‹ค. 

View์™€ Button์‚ฌ์ด ์ œ์•ฝ์„ค์ •
Leading Space๋ฅผ 20์œผ๋กœ!

 

 

4๏ธโƒฃ Horizontal Stack View ์„ค์ •

Horizontal Stack View ์•ˆ์— Vertical Stack View ๋“ค์„ ๋งŒ๋“ค๊ณ  Horizontal Stack View์˜ Distribution์„ Fill Equally๋กœ ์„ค์ •

 

์ด Horizontal Stack View๋„ ์–‘์˜†์— Padding์„ ์ฃผ๊ธฐ ์œ„ํ•ด, ์•ž์—์„œ Button์„ View๋กœ ๊ฐ์‹ธ๋“ฏ์ด Horizontal Stack View๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ View๋กœ ๊ฐ์‹ธ๋Š” ์ž‘์—…์„ ํ•ด์•ผํ•œ๋‹ค.

View์™€ Horizontal Stack View ์‚ฌ์ด์˜ Contraint
์ด๊ฑฐ ๊นŒ์•„์ฅ

 

์™„์„ฑ๋œ ํ™”๋ฉด !

 

 

 

5๏ธโƒฃ ๊ธฐ๋Šฅ ๊ตฌํ˜„

//
//  WeatherViewController.swift
//  Simple Weather
//
//  Created by ์˜ค์˜ˆ์ง„ on 2022/05/17.
//

import UIKit

class WeatherViewController: UIViewController {

    @IBOutlet weak var cityLabel: UILabel!
    @IBOutlet weak var weatherImageView: UIImageView!
    @IBOutlet weak var temperatureLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    let cities = ["Seoul", "Tokyo", "LA", "Seattle"]
    let weathers = ["cloud.fill", "sun.max.fill", "wind", "cloud.sun.rain.fill" ]
    
    // ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ธ์„ ๋•Œ!
    @IBAction func changeButtonTapped(_ sender: Any) {
        
        // ๋„์‹œ๊ฐ€ ๋žœ๋ค์œผ๋กœ
        cityLabel.text = cities.randomElement()
        
        // ๋‚ ์”จ ์ด๋ฏธ์ง€๊ฐ€ ๋žœ๋ค์œผ๋กœ
        let imageName = weathers.randomElement()!
        weatherImageView.image = UIImage(systemName: imageName)?.withRenderingMode(.alwaysOriginal )
        // ๋‚ ์”จ ์ด๋ฏธ์ง€๊ฐ€ ๋žœ๋ค์œผ๋กœ ๋ฐ”๋€” ๋•Œ, ์ƒ‰์ด ์ด์ƒํ•˜๊ฒŒ ๋ณ€ํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด withRenderingMode๋ฅผ alwaysOriginal๋กœ!
        // ์ด๋ ‡๊ฒŒ ์•ˆํ•˜๊ฑฐ๋‚˜ alwaysTemplate์œผ๋กœ ์„ค์ •ํ•˜๋ฉด ๊ธฐ๋ณธ tint color๊ฐ€ ์ž…ํ˜€์ง„ ์ด๋ฏธ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚˜๊ฒŒ ๋œ๋‹ค.
        
        // ์˜จ๋„๊ฐ€ ๋žœ๋ค์œผ๋กœ
        let randomTemp = Int.random(in:10..<30)
        temperatureLabel.text = "\(randomTemp)°"
    }

}

 

 

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] Symbol Roller  (0) 2022.05.12