
Form에서 이름과 콘텐츠를 가지는 경우가 너무 많아서 뷰로 만들어 보았다. 이때 @ViewBuilder를 사용해야 하는데, 구글링을 통해서 얻은 코드로 작동만 되도록 만들어서, 정확한 작동법은 알지 못한다. 나중에 시간내서 @ViewBuilder에 대해서 정리해야 겠다. import SwiftUI struct NamedContent: View { var name: String @ViewBuilder var content: () -> Content var body: some View { HStack { Text(name) .bold() Spacer() content() } } } struct NamedContent_Previews: PreviewProvider { static var previews: s..
iOS 16 이상 TextEditor(text: $text) .scrollContentBackground(.hidden) .background(.red) iOS 15 이하 struct ContentView: View { @State private var text = "" init() { UITextView.appearance().backgroundColor = .clear } var body: some View { List { TextEditor(text: $text) .background(.red) } } }
오늘도 열심히 삽질을 했다. 아니... 지금도 하고 있는 중이다. 이 삽질을 기록해두면 좋을 것 같다는 생각이 들어서 이제 삽질을 기록해 보려고 한다. Form에 TextEditor를 사용하니 TextEditor가 최소 높이가 되어 버렸다. 아마 Form은 자식 뷰의 높이를 최소한으로 제공하고 TextEditor는 최소 높이만 존재하는 것 같다. 그래서 TextEditor에 frame(minHeight:)로 최소 높이를 제공해서 해결할 수 있었다. 하지만 다음 문제점은 TextEditor의 텍스트의 줄이 많아져도 Form이 업스크롤되지 않는 문제가 발생했다. 열심히 구글링해보니 ScrollViewReader로 Form을 넣고 스크롤을 제어할 수 있다고 한다. 하지만 문제점은 TextEditor의 텍스트를..

SwiftUI는 네비게이션 바 디스플레이 모드를 설정할 수 있다. 모드를 설정하기 위해서 .navigationBarTitleDisplayMode 수정자를 사용한다. 모드는 3가지가 있다. - inline - large - automatic # inline 네비게이션 항목의 표준 범위 내에 제목을 표시한다. # large 확장된 네비게이션 항목 내에 큰 제목을 표시한다. # automatic 이전 탐색 네비게이션 아이템에서 디스플레이 모드를 상속한다. struct ContentView: View { var body: some View { NavigationStack { Text("HI") .navigationTitle("Title") .navigationBarTitleDisplayMode(.inline) ..
SwiftUI를 사용하다보면 네비게이션 바를 사용하지 않을 때가 있다. 하지만 네비게이션 바를 사용하지 않아도 공간을 차지고 있다. # iOS 13.0 ~ 17.0 네비게이션 바 공간을 없애기 위해서 .navigationBarHidden(true) 수정자를 사용하면 된다. struct TestView: View { var body: some View { NavigationStack { Text("HI") .navigationBarHidden(true) } } } # iOS 16.0 ~ .navigationBarHidden(true)는 iOS 13.0-17.0까지만 지원한다고 한다. 그래서 iOS16.0 부터는 .toolbar(.hidden, for: .navigationBar) 수정자를 사용해야 한다. ..

SwiftUI의 Form의 배경색상을 얻는 방법은 다음 사이트에서 잘 설명해주고 있다. https://sarunw.com/posts/dark-color-cheat-sheet/ Dark color cheat sheet | Sarunw A cheat sheet that tells you what colors to use to support dark mode. This is a guide for those who want to adopt dark mode, but too lazy to figure out which color to use. sarunw.com 나는 Form의 배경색상을 얻는 방법을 원했다. 일반 배경은 .systemBackground라는 하나의 색상이 사용된다. 하지만 Form은 그룹 색상이 ..

SwiftUI의 TextField의 텍스트를 정렬하려면 .multilineTextAlignment 수정자를 사용하면 된다. // .leading 앞쪽 (디폴트) TextField("name", text: $name) .multilineTextAlignment(.leading) // .center 가운데 TextField("name", text: $name) .multilineTextAlignment(.center) // .trailing 뒤쪽 TextField("name", text: $name) .multilineTextAlignment(.trailing) struct TextView: View { @State private var name = "" var body: some View { VStack(..