ContentView.swift
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | // // ContentView.swift // swiftuidev // // Created by Cairocoders // import SwiftUI struct ContentView: 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 ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } |