Created
March 14, 2021 10:28
-
-
Save prafullakumar/70104af4d7bdd9c97a011c9a7dab0385 to your computer and use it in GitHub Desktop.
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
import SwiftUI | |
struct Demo: View { | |
@State private var text = "" | |
var body: some View { | |
NavigationView { | |
VStack(alignment: .leading){ | |
Text("How are you feeing today?") | |
.font(.title) | |
CustomTextEditor.init(placeholder: "Start typing..", text: $text) | |
.font(.body) | |
.background(Color(UIColor.systemGray6)) | |
.accentColor(.green) | |
.frame(height: 400) | |
.cornerRadius(8) | |
Spacer() | |
}.padding() | |
.navigationTitle("Navigation") | |
} | |
} | |
} | |
struct CustomTextEditor: View { | |
let placeholder: String | |
@Binding var text: String | |
let internalPadding: CGFloat = 5 | |
var body: some View { | |
ZStack(alignment: .topLeading) { | |
if text.isEmpty { | |
Text(placeholder) | |
.foregroundColor(Color.primary.opacity(0.25)) | |
.padding(EdgeInsets(top: 7, leading: 4, bottom: 0, trailing: 0)) | |
.padding(internalPadding) | |
} | |
TextEditor(text: $text) | |
.padding(internalPadding) | |
}.onAppear() { | |
UITextView.appearance().backgroundColor = .clear | |
}.onDisappear() { | |
UITextView.appearance().backgroundColor = nil | |
} | |
} | |
} | |
struct DemoView_Previews: PreviewProvider { | |
static var previews: some View { | |
Demo() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment