41 lines
1.2 KiB
Swift
41 lines
1.2 KiB
Swift
//
|
|
// TextView.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 2024/01/18.
|
|
//
|
|
|
|
import SwiftUI
|
|
import UIKit
|
|
|
|
struct DetectableTextView: UIViewRepresentable {
|
|
var text: String
|
|
var textSize: CGFloat = 11.3
|
|
var font: String = Font.light.rawValue
|
|
|
|
func makeUIView(context: Context) -> UITextView {
|
|
let textView = UITextView()
|
|
_ = textView.layoutManager
|
|
var attributes = [NSAttributedString.Key: Any]()
|
|
let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
|
|
paragraphStyle.lineSpacing = 8
|
|
attributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle
|
|
textView.typingAttributes = attributes
|
|
|
|
textView.isEditable = false // Make it readonly
|
|
textView.backgroundColor = .clear
|
|
textView.isScrollEnabled = true
|
|
textView.dataDetectorTypes = .link
|
|
textView.font = UIFont(name: font, size: textSize)
|
|
textView.textColor = .white
|
|
textView.textContainer.lineFragmentPadding = 0
|
|
textView.textContainerInset = .zero
|
|
|
|
return textView
|
|
}
|
|
|
|
func updateUIView(_ uiView: UITextView, context: Context) {
|
|
uiView.text = text
|
|
}
|
|
}
|