Last active
December 27, 2023 05:25
-
-
Save aaronlab/1cff99fc70c2e39c11087e78429d21e8 to your computer and use it in GitHub Desktop.
SwiftUI TextEditor Placeholder
This file contains hidden or 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
struct TextEditorPlaceHolder: View { | |
@State private var text: String = "" | |
private let screenWidth = UIScreen.main.bounds.width | |
var body: some View { | |
VStack { | |
ZStack(alignment: .leading) { | |
if self.text.isEmpty { | |
VStack { | |
Text("Placeholder") | |
.multilineTextAlignment(.leading) | |
Spacer(minLength: 0) | |
} | |
} | |
TextEditor(text: $text) | |
.padding(.vertical, 20) | |
.padding(.horizontal, 36) | |
.opacity(self.text.isEmpty ? 0.1 : 1) | |
} //: Z | |
.frame(width: self.screenWidth, height: self.screenWidth * 0.583) | |
.overlay( | |
RoundedRectangle(cornerRadius: 8) | |
.stroke() | |
.foregroundColor(.gray) | |
.padding(.horizontal, 16) | |
) | |
} //: V | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suggestion:
Thanks Aaron Lee!