Skip to content

Instantly share code, notes, and snippets.

@Drag0ndust
Created January 27, 2022 13:58
Show Gist options
  • Save Drag0ndust/f003af5984385fe3940f5734bdc129be to your computer and use it in GitHub Desktop.
Save Drag0ndust/f003af5984385fe3940f5734bdc129be to your computer and use it in GitHub Desktop.
SwiftUI: Texteditor with Placeholder
import SwiftUI
struct TextEditorWithPlaceholder: View {
@Binding var text: String
var placeholder: String
var body: some View {
TextEditor(text: $text)
.background(
VStack {
HStack(alignment: .top) {
if text.isEmpty {
Text(placeholder)
}
Spacer()
}
Spacer()
}
.padding(.leading, 5)
.padding(.top, 8.5)
)
}
}
@Drag0ndust
Copy link
Author

You are welcome ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment