Reputation: 11450
Is it possible to stikethrough
a UILabel
at all? I can't seem to find the option...
Upvotes: 13
Views: 9756
Reputation: 4667
NSAttributedString *str=[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%.2f", productOne.priceBefore] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
cell.priceBefore.attributedText = str;
Upvotes: 1
Reputation: 17898
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.
Upvotes: 3
Reputation: 739
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
Upvotes: 9
Reputation: 1942
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.
Upvotes: 1
Reputation: 1707
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.
Upvotes: 4