Let's take a look directly at it:
Requirements: is the table cell inside the state label, the front "state:" is black, the back of the status value is red, they are on the same label, how to do it?
Answer: Really is the meeting is not difficult, the difficult person will not ah, use rich text, easy to fix.
Crap not much to say, directly on the code:
1 //synthesize Rich text based on state values2-(Nsmutableattributedstring *) getstatestring: (NSString *) state{3 4 //the string after the composition5NSString *fullstr = [NSString stringWithFormat:@"Status:%@", State];6 7 //range of Status values8Nsrange range =[Fullstr rangeofstring:state];9 Ten //Color of Status value display OneUicolor *color = [Uicolor kt_colorwithhex:0xff1e00Andalpha:1]; A - //convert a synthesized string to Rich text -Nsmutableattributedstring *attributedstr =[[Nsmutableattributedstring alloc] initwithstring:fullstr]; the - //add an attribute to the corresponding range - [Attributedstr Addattributes:@{nsforegroundcolorattributename:color} Range:range]; - + returnAttributedstr; -}
Then assign the rich text directly to the label's Attributedtext
1 self.stateLabel.attributedText = [self getstatestring:@ " not received order "];
A uilabel different parts show different colors