如何在同一串文字中凸现富文本-EmphasizeString
What’s itEmphasizeString(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 st
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:
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)