๐ ๋๋ฒ์งธ ํ๋ก์ ํธ
๋ฒํผ์ ํด๋ฆญํ ๋ ๋ง๋ค ๋๋ค์ผ๋ก ๋ ์จ, ์จ๋, ๋์๊ฐ ๋ฐ๋๋ ์ฑ์ ๋ง๋ค์ด๋ณด์
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 ๋ง๋ค๊ธฐ
- Storyboard ID? View Controller์ Storyboard์์ ์ฐพ์ ๋ ์ฌ์ฉํ๋ ID
3๏ธโฃ ํ๋ฉด์ค์ (๋ ์ด์์ ์ค์ )
Stack View์์๋ Button(๊ทธ ์ธ ๋ค๋ฅธ ์์ดํ ๋)์ด ์์์ผ๋ก Fill๋๊ธฐ ๋๋ฌธ์ ๊ฐ์์ View๋ฅผ ๋ง๋ค๊ณ ๊ทธ ์์ Button์ ๋ฃ์ด ์์์ Padding์ ์ค์ผ ํ๋ค.
4๏ธโฃ Horizontal Stack View ์ค์
์ด Horizontal Stack View๋ ์์์ Padding์ ์ฃผ๊ธฐ ์ํด, ์์์ Button์ View๋ก ๊ฐ์ธ๋ฏ์ด Horizontal Stack View๋ ๋ง์ฐฌ๊ฐ์ง๋ก View๋ก ๊ฐ์ธ๋ ์์ ์ ํด์ผํ๋ค.
์์ฑ๋ ํ๋ฉด !
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 |