mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-04-05 06:14:59 +00:00
34 lines
1.3 KiB
Swift
34 lines
1.3 KiB
Swift
// Copyright © 2020 Australian Government All rights reserved.
|
|
|
|
import UIKit
|
|
|
|
extension UITextView {
|
|
func addLink(_ linkString: String, enclosedIn marker: String) {
|
|
guard let attributedText = attributedText else { return }
|
|
|
|
let mutableString = NSMutableAttributedString(attributedString: attributedText)
|
|
mutableString.addLink(enclosedIn: marker, urlString: linkString)
|
|
self.attributedText = mutableString
|
|
tintColor = UIColor.covidSafeColor
|
|
}
|
|
|
|
func addAllBold(enclosedIn marker: String) {
|
|
guard let attributedText = attributedText else { return }
|
|
|
|
let mutableString = NSMutableAttributedString(attributedString: attributedText)
|
|
while mutableString.canParseOccurence(elementStartRegex: marker, elementEndRegex: marker) {
|
|
mutableString.addBold(enclosedIn: marker)
|
|
}
|
|
self.attributedText = mutableString
|
|
}
|
|
|
|
func parseHTMLTags() {
|
|
guard let attributedText = attributedText else { return }
|
|
|
|
let mutableString = NSMutableAttributedString(attributedString: attributedText)
|
|
mutableString.parseHTMLLinks()
|
|
mutableString.parseBoldTags()
|
|
self.attributedText = mutableString
|
|
tintColor = UIColor.covidSafeColor
|
|
}
|
|
}
|