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