There is no api for it (yet). BUT YOU CAN:
Use a custom placeholder
modifier to show any view as the holder of any other view! e.g:
TextField("", text: $text)
.placeholder(when: text.isEmpty) {
Text("Placeholder recreated").foregroundColor(.gray)
}
?? It's a simple ZStack
that you can in a View
extension like:
extension View {
func placeholder<Content: View>(
when shouldShow: Bool,
alignment: Alignment = .leading,
@ViewBuilder placeholder: () -> Content) -> some View {
ZStack(alignment: alignment) {
placeholder().opacity(shouldShow ? 1 : 0)
self
}
}
}
?? Now you can apply any kind of style to the placeholder like this gradient placeholder with image:
? If you are interested, Here is how to apply resizable gradient on any view
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…