Is it possible to stikethrough
a UILabel
at all? I can't seem to find the option...
Asked
Active
Viewed 9,714 times
13

Girish
- 4,692
- 4
- 35
- 55

Lee Armstrong
- 11,420
- 15
- 74
- 122
5 Answers
9
This is an old question and newer information is available.
Starting in iOS 6, we have NSAttributedString.
For pre iOS 6, I would look at TTTAttributedLabel

Stephen
- 741
- 8
- 18
4
You could create another UILabel above your label and use an en dash character:
label.text = @"––––––––––––––––––";
Caveat: works with Helvetica (system default). It may not work with other fonts.

greenisus
- 1,707
- 14
- 17
3
iPhone doesn't support attributed strings (which is usually the way you'd do this in Cocoa), so I don't believe it's possible.
You could subclass UILabel
and draw the strikethrough
yourself. I've also seen some people use a UIWebView
to do this type of thing, but that seems like overkill to me.

Girish
- 4,692
- 4
- 35
- 55

zpasternack
- 17,838
- 2
- 63
- 81
-
Thanks, bit rubbish though! blimin Apple! – Lee Armstrong Jun 28 '09 at 15:25
-
Starting iOS 6, it does support NSAttributedString. See my post – Stephen Dec 15 '12 at 08:53
1
UIView* slabel = [[UIView alloc] initWithFrame:CGRectMake(label.frame.origin.x, label.frame.origin.y+10, label.frame.size.width, 2)];
[self addSubview:slabel];
[slabel setBackgroundColor:label.textColor];
You can add a view over UILabel and style it with label properties.

aytek
- 1,842
- 24
- 32
1
NSAttributedString *str=[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%.2f", productOne.priceBefore] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
cell.priceBefore.attributedText = str;

Gank
- 4,507
- 4
- 49
- 45