반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- RxCocoa
- dismiss
- NullObject
- swift6
- URL(string:)
- RxSwift
- nonisolated
- @Binding
- Creating Operators
- typeorm
- init
- IOS
- RFC1738/1808
- subject
- nestjs
- Operators
- NavigationLink
- vim
- @Environment
- Xcode
- @EnvironmentObject
- graphql
- Operater
- operator
- Bug
- SwiftUI
- ios14
- @State
- init?
- SWIFT
Archives
- Today
- Total
Tunko Development Diary
[iOS][SwiftUI] VStack, HStack, ZStack 정리 본문
VStack
struct ContentView: View {
var body: some View {
VStack {
Text("1").frame(width: 50, height: 50, alignment: .center)
Text("2").frame(width: 50, height: 50, alignment: .center)
Text("3").frame(width: 50, height: 50, alignment: .center)
}
}
}
HStack
struct ContentView: View {
var body: some View {
HStack {
Text("1").frame(width: 50, height: 50, alignment: .center)
Text("2").frame(width: 50, height: 50, alignment: .center)
Text("3").frame(width: 50, height: 50, alignment: .center)
}
}
}
VStack (3개의 예시로 작성했습니다.)
예1)
struct ContentView: View {
var body: some View {
ZStack {
Text("1").font(.title).frame(width: 50, height: 50, alignment: .center).border(Color.black, width: 1)
Text("2").font(.headline).frame(width: 80, height: 80, alignment: .center).border(Color.black, width: 1)
Text("3").font(.largeTitle).frame(width: 110, height: 110, alignment: .center).border(Color.black, width: 1)
}
}
}
예2)
VStack 의 경우 겹치기 때문에 font와 border를 설정해보았다.
화면에 가장 앞쪽에 있는건 “3”이라 적힌 Text뷰이다.
다르게 예시를 들어보겠습니다.
struct ContentView: View {
var body: some View {
ZStack {
Text("1").font(.title).frame(width: 50, height: 50, alignment: .center).border(Color.black, width: 1).background(Color.yellow)
Text("2").font(.headline).frame(width: 80, height: 80, alignment: .center).border(Color.black, width: 1).background(Color.blue)
Text("3").font(.largeTitle).frame(width: 110, height: 110, alignment: .center).border(Color.black, width: 1).background(Color.red)
}
}
}
예3) - 배치 변경
struct ContentView: View {
var body: some View {
ZStack {
Text("3").font(.largeTitle).frame(width: 110, height: 110, alignment: .center).border(Color.black, width: 1).background(Color.red)
Text("2").font(.headline).frame(width: 80, height: 80, alignment: .center).border(Color.black, width: 1).background(Color.blue)
Text("1").font(.title).frame(width: 50, height: 50, alignment: .center).border(Color.black, width: 1).background(Color.yellow)
}
}
}
결론적으로 스택에 추가된 순서가 중요합니다.
반응형
'Development > iOS 개발' 카테고리의 다른 글
[iOS][SwiftUI] alignment 정리 (0) | 2021.02.15 |
---|---|
[iOS][SwiftUI] Spacer 정리 (0) | 2021.02.15 |
[iOS][SwfitUI] SwiftUI life cycle에서 AppDelegate사용하기 (0) | 2021.02.14 |
[iOS14][SwfitUI] SwiftUI2 life cycle 에서 딥링크 처리 (0) | 2021.02.14 |
[iOS14][SwfitUI] SwiftUI2 App life cycle 정리 (0) | 2021.02.14 |
Comments