Here is a simple solution that works for me:
VStack (alignment: .leading) {
ZStack(alignment: .leading) {
TextEditor(text: $comment)
.frame(minHeight: 50)
Text("Comment")
.frame(width: 100, alignment: .leading)
.foregroundColor(Color(.systemGray2))
.padding(.top, -22)
.padding(.leading, 5)
.opacity(self.comment == "" ? 100 : 0)
}
}
It works rven if a user clicks/taps on the TextEditor, enters nothing, and then clicks/taps outside of the TextEdit.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: