func makeUIView()

in Broadcasting/Views/Components/TextWithHyperlink.swift [21:56]


    func makeUIView(context: Context) -> UITextView {
        let textAttributes: [NSAttributedString.Key : Any] = [
            NSAttributedString.Key.font: font,
            NSAttributedString.Key.foregroundColor: UIColor(cgColor: textColor.cgColor!)
        ]
        let hyperlinkTextAttributes: [NSAttributedString.Key : Any] = [
            NSAttributedString.Key.font: font,
            NSAttributedString.Key.foregroundColor: UIColor(cgColor: urlColor.cgColor!),
            NSAttributedString.Key.underlineStyle: underlineStyle.rawValue,
            NSAttributedString.Key.underlineColor: UIColor(cgColor: urlColor.cgColor!),
            NSAttributedString.Key.link: url
        ]

        let text = NSMutableAttributedString(string: leadingText)
        text.addAttributes(textAttributes, range: NSRange(location: 0, length: text.length))

        let textWithHyperlink = NSMutableAttributedString(string: urlLabel)
        textWithHyperlink.addAttributes(hyperlinkTextAttributes, range: NSRange(location: 0, length: textWithHyperlink.length))

        let trailing = NSMutableAttributedString(string: trailingText)
        trailing.addAttributes(textAttributes, range: NSRange(location: 0, length: trailing.length))

        text.append(textWithHyperlink)
        text.append(trailing)

        let textView = UITextView()
        textView.attributedText = text
        textView.linkTextAttributes = hyperlinkTextAttributes

        textView.isEditable = false
        textView.textAlignment = textAlignment
        textView.backgroundColor = .clear
        textView.isUserInteractionEnabled = false

        return textView
    }