How does TTTAttributedLabel highlight multiple strings? tttattributedlabel

Source: Internet
Author: User

How does TTTAttributedLabel highlight multiple strings? tttattributedlabel

 

TTTAttributedLabel is used to highlight multiple strings.

Each string needs to be matched to obtain all the nsange to be highlighted. Then, the NSMutableAttributedString is used to add attribute for each nsange.

 

The first is the string matching algorithm. You can study the kmp and bm algorithms. Here, I directly use the NSRegularExpression that comes with OC for regular expression matching. It should be the simplest and most direct method.

 

Input the string text, and the string patterns to be highlighted. The regular expression is the "|" set of the string. the string is case insensitive based on the regular expression, and then the NSTextCheckingResult is enumerated, save it in the array, and then you can set the label font.

The setText: afterInheritingLabelAttributesAndConfiguringWithBlock of TTTAttribute is used here. This method traverses all NSTextCheckingResult objects in the code block and sets the color font of the nsange to complete the desired effect.

 

Of course, you can also crop strings. One of my own solutions is to crop strings with the maximum length required.

Because of the various requirements and different cropping parts, this can only help you. If you have interesting or wonderful cropping requirements, please contact me.

 

Attached:

 

For specific source code, visit http://www.cnblogs.com/sely-ios/p/4552134.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.