2009-06-28 65 views

回答

3

iPhone不支持属性字符串(这通常是你在Cocoa中这样做的方式),所以我不相信这是可能的。

您可以继承UILabel并自己绘制strikethrough。我也看到一些人使用UIWebView做这种事情,但这对我来说似乎有点矫枉过正。

+0

谢谢,有点垃圾,但! blimin苹果! – 2009-06-28 15:25:49

3

你可以创建你的标签上方另一个的UILabel和使用破折号字符:

label.text = @"––––––––––––––––––"; 

警告:可与黑体(系统默认)。它可能不适用于其他字体。

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

您可以通过UILabel添加视图并使用标签属性对其进行设置。

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

cell.priceBefore.attributedText = str;