SwiftUI/Views
[SwiftUI] TextEditor에 PlaceHolder 추가하기
_히처리_
2023. 9. 11. 21:20
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)
}