Tttattributedlabel how to highlight multiple strings

Source: Internet
Author: User

Tttattributedlabel the highlighting of multiple strings.

Each string needs to be matched to get all the nsrange that need to be highlighted, and then use nsmutableattributedstring to add attribute to each Nsrange

The first is the string matching algorithm, you can study the next KMP and BM algorithm, here I directly with the OC nsregularexpression to do regular expression matching, it should be the simplest direct way

Passing in the string text, and the character string that needs highlighting, the regular expression is the "|" collection of strings, patterns the case of strings based on regular expressions, and then enumerates the generated Nstextcheckingresult, saved in the array, Next, you can set the label font

Here is Tttattribute's settext:afterinheritinglabelattributesandconfiguringwithblock: Method, The Nstextcheckingresult object is traversed in the code block, and the color font is set on the nsrange to achieve the desired effect.

Of course, you can also cut the string, and one of my own solutions is to give a desired maximum string length to be cropped

Because of the variety of requirements, cutting parts are not the same, this can only help here, if there are more interesting or wonderful tailoring needs, welcome and I exchange.

Attach one:

Specific source please visit http://www.cnblogs.com/sely-ios/p/4552134.html

Tttattributedlabel how to highlight multiple strings

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.