Created
March 10, 2024 08:21
-
-
Save kipsong133/68902bf0ad5ef3e1b61a38b85744e3b5 to your computer and use it in GitHub Desktop.
[SwiftUI][Placeholder][Hinttext] TextEditor(TextView, multiple line textfiled) Placeholder View #SwiftUI
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 UplodePostView: View { | |
@State private var text: String = "" | |
var body: some View { | |
NavigationView { | |
Form { | |
Section { | |
TextEditorWithPlaceholder(text: $text, placeholder: "Write something...") | |
} | |
} | |
} | |
} | |
} | |
struct TextEditorWithPlaceholder: View { | |
@Binding var text: String | |
let placeholder: String | |
var body: some View { | |
ZStack(alignment: .leading) { | |
if text.isEmpty { | |
VStack { | |
Text(placeholder) | |
.padding(.top, 7) | |
.padding(.leading, 6) | |
.customFont(size: 16, fontFamily: .wantedSans(.regular)) | |
.foregroundStyle(Color.black.opacity(0.6)) | |
Spacer() | |
} | |
} | |
VStack { | |
TextEditor(text: $text) | |
.customFont(size: 16, fontFamily: .wantedSans(.regular)) | |
.frame(minHeight: 150, maxHeight: 300) | |
.opacity(text.isEmpty ? 0.85 : 1) | |
Spacer() | |
} | |
} | |
} | |
} | |
#Preview { | |
UplodePostView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment