13

Is it possible to stikethrough a UILabel at all? I can't seem to find the option...

Girish
  • 4,692
  • 4
  • 35
  • 55
Lee Armstrong
  • 11,420
  • 15
  • 74
  • 122

5 Answers5

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
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