์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- reactorkit
- ํ๋ก๊ทธ๋๋จธ์ค
- Flutter
- ํจ์คํธ์บ ํผ์ค
- BOJ
- combine
- designpattern
- visionOS
- node.js
- arkit
- ๋ฐฑ์ค
- Kuring
- UIKit
- CollectionView
- SnapKit
- swift
- Lv2
- XCTest
- rxcocoa
- raywenderlich
- Xcode
- MVVM
- RxSwift
- TCA
- BFS
- SwiftUI
- ios
- Swfit
- realm
- tableView
Archives
- Today
- Total
lgvv98
[SwiftUI] VStack, HStack, ZStack ๋ณธ๋ฌธ
VStack, HStack, ZStack
โ ์คํ๋ทฐ์ ๋ํด์ ์์๋ณด์.
โ VStack
import SwiftUI
struct MyVstack : View {
var body: some View {
// VStack์๋ ๊ธฐ๋ณธ์ ์ธ spacing์ด ์์ด์ 0์ผ๋ก ํด์ฃผ๊ธฐ
// alignment๋ ์ ๋ ฌ ์ต์
VStack(alignment: .trailing, spacing: 0) {
// ์ฐ์ธก์ผ๋ก ๋ถ์ด๊ธฐ ์ํ 3๊ฐ์ง ๋ฐฉ๋ฒ!
// ๊ณต๊ฐ์ ์์ ์ฃผ์ด์ ์ ๋ ฌํ๊ธฐ
// Spacer()
// opacity(0) ํตํด์ ์ ์ ์๋ณด์ด๊ฒ ํ๋ค.
Divider().opacity(0)
// ์์ Rectangle ํ๋ ๋ ๋ง๋ค๊ธฐ
// Rectangle()
// .frame(height: 1)
//
Text("๊ธ์")
.font(.system(size: 30))
.fontWeight(.heavy)
// .padding(.bottom, 100) // ์๋์ ์ฌ๋ฐฑ์ฃผ๊ธฐ
Rectangle()
.frame(width: 100, height: 100)
.foregroundColor(Color.red)
// .padding(.vertical, 100) // ์์ง์ผ๋ก ์ฌ๋ฐฑ์ฃผ๊ธฐ
Rectangle()
.frame(width: 100, height: 100)
.foregroundColor(Color.yellow)
// spacer๋ฅผ ํ์ฉํด์ ์ํ๋ ๋งํผ ํฌ๊ธฐ ์กฐ์
Spacer()
.frame(height: 50)
Rectangle()
.frame(width: 100, height: 100)
.foregroundColor(Color.blue)
// ์์ Spacer 1๊ฐ ์๋์ 3๊ฐ ๋์ด์ ์์๋๋ก 1:3 ๋งํผ ๊ณต๊ฐ์ ํ๋ณดํจ
// Spacer()
// Spacer()
// Spacer()
} // VStack
.frame(width: 300) // width๋ง 300 height๋ ์๋์ง์
.background(Color.green)
// .edgesIgnoringSafeArea(.all)
}
}
โ HStack
import SwiftUI
struct MyHstack : View {
var body: some View {
HStack(alignment: .center) {
// Divider()
// Rectangle()
// .frame(width: 100)
// .foregroundColor(.red)
// Rectangle()
// .frame(width: 100, height: 100)
// .foregroundColor(.red)
Image(systemName: "flame.fill")
.foregroundColor(.white)
.font(.system(size: 70)) // systemImage์์ ํฌ๊ธฐ ์กฐ์ ํ๋ ๋ฐฉ๋ฒ
Rectangle()
.frame(width: 100, height: 100)
.foregroundColor(.yellow)
Rectangle()
.frame(width: 100, height: 100)
.foregroundColor(.blue)
}
.padding()
.background(Color.green)
}
}
โ ZStack
zIndex๋ ๊ธฐ๋ณธ์ด 0์ด๋ฉฐ, 0์ธต๋ถํฐ ์ซ์๊ฐ ๋์์ง ์๋ก ์์ ์๋ค๊ณ ์๊ฐํ๊ธฐ.
import SwiftUI
struct MyZstack : View {
var body: some View {
ZStack {
Rectangle()
.frame(width: 50, height: 50)
.foregroundColor(Color.yellow)
.zIndex(2) // zIndexํตํด์ index์กฐ์
.offset(y: -100)
// .padding(.bottom, 100)
Rectangle()
.frame(width: 100, height: 100)
.foregroundColor(Color.red)
.zIndex(1)
Rectangle()
.frame(width: 150, height: 150)
.foregroundColor(Color.blue)
.zIndex(0)
}
}
}
'apple > ๐ SwiftUI & Combine' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SwiftUI] NavigationView (0) | 2022.05.18 |
---|---|
[SwiftUI] List (tableView in UIKit) (0) | 2022.05.18 |
[SwiftUI] Alert (0) | 2022.05.18 |
[SwiftUI] How to set Image in SwiftUI (0) | 2022.05.18 |
[SwiftUI] Info.plist๊ฐ ์์ ๋๐ค (0) | 2022.02.23 |
Comments