ios - Revert strikeThrough text to plain text after some operation is performed in TTTAttributedLabel -


i using code change color of label , set text strike through:

sliderlabel = [[tttattributedlabel alloc] initwithframe:cgrectmake(10, 260, 310, 30)];  sliderlabel.font = [uifont fontwithname:@"optima-bold" size:14]; [sliderlabel settag:112]; sliderlabel.linebreakmode = uilinebreakmodewordwrap; [sliderlabel setbackgroundcolor:[uicolor clearcolor]];  nsstring *sliderlabeltext = [nsstring stringwithformat:@"change to: in-progress (%d %%)",(int)slider.value]; [sliderlabel settext:sliderlabeltext afterinheritinglabelattributesandconfiguringwithblock:^ nsmutableattributedstring *(nsmutableattributedstring *mutableattributedstring) {     nsrange boldrange = [[mutableattributedstring string] rangeofstring:[nsstring stringwithformat:@"in-progress (%d %%)",(int)slider.value] options:nscaseinsensitivesearch];     nsrange strikerange = [[mutableattributedstring string] rangeofstring:sliderlabeltext options:nscaseinsensitivesearch];     uifont *boldsystemfont = [uifont fontwithname:@"optima-bold" size:14];     ctfontref font = ctfontcreatewithname((cfstringref)boldsystemfont.fontname, boldsystemfont.pointsize, null);     if (font) {         [mutableattributedstring addattribute:(nsstring *)kctforegroundcolorattributename value:(id)[uicolor colorwithred:8/255.0 green:156/255.0 blue:94/255.0 alpha:1.0].cgcolor range:boldrange];//34-139-34         [mutableattributedstring addattribute:ktttstrikeoutattributename value:[nsnumber numberwithbool:yes] range:strikerange];         cfrelease(font);     }      return mutableattributedstring; }]; [self.view addsubview:sliderlabel]; [sliderlabel release]; 

now want without strike through when perform operation click on button, passing [nsnumber numberwithbool:no] in addattribute:value:range doesnt work. suggestions?

try additions.

@implementation tttattributedlabel (additions)  - (void)setstrikethroughon:(bool)isstrikethrough {     nsstring* text = self.text;     [self settext:text afterinheritinglabelattributesandconfiguringwithblock:^        nsmutableattributedstring *(nsmutableattributedstring *mutableattributedstring) {     nsrange strikerange = [[mutableattributedstring string] rangeofstring:text options:nscaseinsensitivesearch];     [mutableattributedstring addattribute:ktttstrikeoutattributename value:[nsnumber numberwithbool:isstrikethrough] range:strikerange];     return mutableattributedstring; }];  // must trigger redraw [self setneedsdisplay]; }  @end 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -