What’s it

EmphasizeString(https://gitee.com/kmyhy/emphasizedstring) 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 thewww.yourdomain.comlook like an url which has an underline textdecoration 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 textsalonlabandme.comclickable and looks like this:

原文地址:https://blog.csdn.net/kmyhy/article/details/124558553

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_45312.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注