Last active
April 17, 2020 19:16
-
-
Save Sangsom/281248066a21f9ce8173d78a5d49366f to your computer and use it in GitHub Desktop.
This is a custom multiline SwiftUI TextView integrated from UITextView
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 | |
import UIKit | |
struct NotesTextView: UIViewRepresentable { | |
@Binding var text: String | |
class Coordinator: NSObject, UITextViewDelegate { | |
@Binding var text: String | |
init(text: Binding<String>) { | |
_text = text | |
} | |
func textViewDidChangeSelection(_ textView: UITextView) { | |
text = textView.text ?? "" | |
} | |
} | |
func makeUIView(context: Context) -> UITextView { | |
let textView = UITextView(frame: .zero) | |
textView.delegate = context.coordinator | |
textView.font = UIFont.systemFont(ofSize: 17, weight: .regular) | |
textView.textContainerInset = UIEdgeInsets(top: 8, left: -5, bottom: 8, right: 0) | |
return textView | |
} | |
func makeCoordinator() -> Coordinator { | |
return Coordinator(text: $text) | |
} | |
func updateUIView(_ uiView: UITextView, context: Context) { | |
uiView.text = text | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment