What’s it
EmphasizeString(https://gitee.com/kmyhy/emphasized-string) is an extension that it help you to emphasize, highlight, underline, style specific sub-strings in a string. For example, given a string said ‘Pls login now at www.yourdomain.com’, you can make the ‘www.yourdomain.com’ look like an url which has an underline text-decoration with this extension.
EmphasizeString is extremely easy to use, please keep reading.
How to use
EmphasizedString extend from String, but to be convenient, it also include 2 UIKit extension: UILabel and UITextView. Absolutely, feel free to extend it to other UIKit to take advantage of its functionality.
UILabel extension
You can use this extension to customize your UILabel’s text style:
label.text = "your special conditioner"
label.setEmphasizedText("conditioner", emphasizedFont: UIFont.boldSystemFont(ofSize: 20), emphasizedColor: UIColor.red)
It looks like:
Other than change text color and font, you can do more better like this:
let attributes = [
NSAttributedString.Key.underlineStyle: 1
]
label.setEmphasizedText("conditioner", emphasizedAttributes: attributes)
You can see that:
UITextView extention
Sometime, we need to insert some clickable rich-text element into our string. we can make it by this extension:
...
messageTextView.setLinkedText("salonlabandme.com", linkTo: "http://salonlabandme.com")
It makes the text ‘salonlabandme.com’ clickable and looks like this:
|