parent
8def448ca7
commit
a0fa722e11
@ -1,48 +0,0 @@ |
||||
// |
||||
// TextView.swift |
||||
// SwiftUITextViewDemo |
||||
// |
||||
// Created by Simon Ng on 7/5/2020. |
||||
// Copyright © 2020 AppCoda. All rights reserved. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct MultiLineTextView: UIViewRepresentable { |
||||
|
||||
@Binding var text: String |
||||
@Binding var textStyle: UIFont.TextStyle |
||||
|
||||
func makeUIView(context: Context) -> UITextView { |
||||
let textView = UITextView() |
||||
|
||||
textView.delegate = context.coordinator |
||||
textView.font = UIFont.preferredFont(forTextStyle: textStyle) |
||||
textView.autocapitalizationType = .sentences |
||||
textView.isSelectable = true |
||||
textView.isUserInteractionEnabled = true |
||||
|
||||
return textView |
||||
} |
||||
|
||||
func updateUIView(_ uiView: UITextView, context: Context) { |
||||
uiView.text = text |
||||
uiView.font = UIFont.preferredFont(forTextStyle: textStyle) |
||||
} |
||||
|
||||
func makeCoordinator() -> Coordinator { |
||||
Coordinator($text) |
||||
} |
||||
|
||||
class Coordinator: NSObject, UITextViewDelegate { |
||||
var text: Binding<String> |
||||
|
||||
init(_ text: Binding<String>) { |
||||
self.text = text |
||||
} |
||||
|
||||
func textViewDidChange(_ textView: UITextView) { |
||||
self.text.wrappedValue = textView.text |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue