0

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?

Akhilrajtr
  • 5,122
  • 3
  • 17
  • 30
ENG618
  • 974
  • 1
  • 12
  • 31

2 Answers2

0

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.

ENG618
  • 974
  • 1
  • 12
  • 31
Zia
  • 14,163
  • 7
  • 37
  • 55
0

Hey got some links for you ,might be helpful for you. Also got answer to strike-through for iOS version below 6.

link1

link2

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;
Community
  • 1
  • 1
nikhil84
  • 3,217
  • 3
  • 19
  • 40