Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kipsong133/68902bf0ad5ef3e1b61a38b85744e3b5 to your computer and use it in GitHub Desktop.
Save kipsong133/68902bf0ad5ef3e1b61a38b85744e3b5 to your computer and use it in GitHub Desktop.
[SwiftUI][Placeholder][Hinttext] TextEditor(TextView, multiple line textfiled) Placeholder View #SwiftUI
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