我目前正在努力解决在许多UITableViewCell
s 中显示删除线文本的需要。用 HTML 编写的东西看起来像
<strike>99 欧元</strike> 节省 50% => 现在 49 欧元
我不想UIWebView
仅将 a 用于单行文本,尤其是在 small UITableViewCell
s 中使用它。我知道有可重复使用的单元格,但我想尽可能以更节省内存的方式保存。
所以...我在AliSoftware 的-replacementNSAttributedString
的帮助下使用 s 。它仅从 iOS 4.0 开始可用这一事实没有问题,因为我们使用各种仅与 4.0 兼容的东西。UILabel
OHAttributedLabel
我可以设法创建属性字符串,它在 中显示文本OHAttributedLabel
,好的,这很酷。但我无法实现的是设置“删除线”或“删除线”属性。
基本上我是这样的:
NSString *price = [NSString stringWithFormat:@"%01.2f €", product.price]; NSString *rate = [NSString stringWithFormat:@" -%01.0f%%", product.reductionRate]; NSMutableAttributedString *s = [NSMutableAttributedString attributesStringWithString:price]; [s addAttribute:NSStrikethroughStyleAttributeName 值:[NSNumber numberWithInteger:NSUnderlinePatternSolid | NSUnderlineStyleSingle] 范围:NSRangeFromString(price)]; [attributedLabel setAttributedText:s];
但是在这里,这三个NS*
常量是未定义的。我已经导入CoreText.h
, Foundation/NSAttributedString.h
,但无济于事。我在网上的某个地方看到过
NSStrikethroughStyleAttributeName = @"NSStrikethroughStyleAttributeName"
,NSUnderlinePatternSolid = 0
和NSUnderlineStyleSingle = 1
, 但是硬编码这些值并没有给出任何东西。我通过自动完成得到的一件事是等效的kCT...*
常量,但是有kCTUnderlineStyleAttributeName
, kCTStrokeWidthAttributeName
, ... 但没有提到kCTStrikethrough
_anything。
我应该怎么做才能显示 *$|#!@ 一条删除线?