Question

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?

Was it helpful?

Solution

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;

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top