Here's my take on the ZStack method:
ZStack(alignment: .topLeading) {
TextEditor(text: $draftPreface)
.frame(height: 100)
.border(Color(uiColor: .opaqueSeparator), width: 0.5)
Text("preface").fontWeight(.light).foregroundColor(.black.opacity(0.25)).padding(8).hidden(!draftPreface.isEmpty)
}
I extended View with a conditional .hidden:
extension View {
@ViewBuilder public func hidden(_ shouldHide: Bool) -> some View {
switch shouldHide {
case true: self.hidden()
case false: self
}
}
}
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: