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