I'm working on a shopping list app, and I'm wanting to format the text as strikethrough
when selecting a cell, not quite sure how to implement this.
I'm assuming I should toggle this effect in the didSelectRowAtIndexPath:
method, but I'm not sure.
Any thoughts?
I don't know if this is the best way to do it but it's definitely a way
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:cell.textLabel.text];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
value:@2
range:NSMakeRange(0, [attributeString length])];
[attributeString addAttribute:NSStrikethroughColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, [attributeString length])];
cell.textLabel.attributedText = attributeString;
You can change the color of the strikethrough as you please.
Hey got some links for you ,might be helpful for you. Also got answer to strike-through for iOS version below 6.
I got below code working for iOS 6 and above
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc]initWithString:@"PROVIDE_YOUR_STRING"];
[attString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(0,[attString length])];
_label.attributedText = attString;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.