mobile-ios/CovidSafe/UITextView + Extensions.swift

36 lines
1.3 KiB
Swift
Raw Normal View History

2020-05-08 07:49:14 +00:00
// 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
}
2020-07-21 05:42:48 +00:00
2020-12-19 05:13:44 +00:00
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() {
2020-07-21 05:42:48 +00:00
guard let attributedText = attributedText else { return }
let mutableString = NSMutableAttributedString(attributedString: attributedText)
mutableString.parseHTMLLinks()
2020-12-19 05:13:44 +00:00
mutableString.parseBoldTags()
2021-12-10 08:05:42 +00:00
mutableString.parseItalicTags()
2020-07-21 05:42:48 +00:00
self.attributedText = mutableString
2020-08-03 06:01:39 +00:00
tintColor = UIColor.covidSafeColor
2020-07-21 05:42:48 +00:00
}
2020-05-08 07:49:14 +00:00
}