Created
January 27, 2022 13:58
-
-
Save Drag0ndust/f003af5984385fe3940f5734bdc129be to your computer and use it in GitHub Desktop.
SwiftUI: Texteditor with Placeholder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are welcome ;)