티스토리 뷰
TextEditor에는 PlaceHolder를 설정할 수 없다.
그래서 ZStack을 이용해서 TextEditor의 텍스트가 빈문자열인 경우, PlaceHolder로 사용할 Text를 보이게 하면 된다.
ZStack(alignment: .topLeading) {
if content.isEmpty {
Text("content")
.padding(7)
.foregroundColor(Color(uiColor: .placeholderText))
} else {
EmptyView()
}
TextEditor(text: $content)
}
'SwiftUI > Views' 카테고리의 다른 글
[SwiftUI] Form에서 스크롤 시 키보드 숨기기 (0) | 2023.09.14 |
---|---|
[SwiftUI] TextEditor 크기를 구하는 방법 (0) | 2023.09.13 |
[SwiftUI] @ViewBuilder (0) | 2023.08.26 |
[SwiftUI] TextEditor 배경색 변경하기 (0) | 2023.08.26 |
[SwiftUI] Form 배경색상, 시스템 색상 얻는 방법 (0) | 2023.08.24 |
댓글