1. Issues encountered with adding a strikethrough method
-(void) Lastlabeldeal: (NSString *) str1 string: (NSString *) str2 Label: (UILabel *) label{
Nsmutableattributedstring
*STR = [[Nsmutableattributedstring alloc] initwithstring:[nsstring stringwithformat:@ "%@%@", STR1,STR2]];
[Str addattribute:nsstrikethroughstyleattributename value:@ (nsunderlinestylesingle| Nsunderlinepatternsolid) Range:nsmakerange (2, str1.length-2)];
[Str
Addattribute:nsforegroundcolorattributename Value:[uicolor Redcolor] Range:nsmakerange (str1.length + 2,str2.length) ];
The following 3 lines of code are for the label part of the content of the strikethrough (this is used before iOS10.3, no problem, but after 10.3 this implementation will be ineffective)
[Str addattribute:nsstrikethroughstyleattributename value:@ (nsunderlinepatternsolid| Nsunderlinestylesingle) Range:nsmakerange (2, str1.length-2)];
[Str addattribute:nsfontattributename value:[uifont Systemfontofsize:12] Range:nsmakerange (2, str1.length-2)];
[Str addattribute:nsforegroundcolorattributename value:[uicolor Redcolor] Range:nsmakerange (2, str1.length-2)];
Label.attributedtext
= str;
}
2. Final Solution (the above 3 lines of code merge together and eventually achieve the effect)
-(void) Lastlabeldeal: (NSString *) str1 string: (NSString *) str2 Label: (UILabel *) label{
Nsmutableattributedstring
*STR = [[Nsmutableattributedstring alloc] initwithstring:[nsstring stringwithformat:@ "%@%@", STR1,STR2]];
[Str addattribute:nsstrikethroughstyleattributename value:@ (nsunderlinestylesingle| Nsunderlinepatternsolid) Range:nsmakerange (2, str1.length-2)];
[Str
Addattribute:nsforegroundcolorattributename Value:[uicolor Redcolor] Range:nsmakerange (str1.length + 2,str2.length) ];
The above 3 lines of code merge together and eventually achieve the effect
[Str addattributes:@{
nsstrikethroughstyleattributename:@ (Nsunderlinestylethick),
Nsforegroundcolorattributename:
[Uicolor Lightgraycolor],
Nsbaselineoffsetattributename:
@ (0),
Nsfontattributename: [Uifont Systemfontofsize:12]
} range:nsmakerange (2, str1.length-2)];
Label.attributedtext
= str;
}
IOS label adds strikethrough (strikethrough) encounters the pit