如何通过颜色改变罢工?

时间:2015-10-21 11:38:05

标签: ios objective-c nsattributedstring

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Old price"];
[str addAttribute:NSStrikethroughStyleAttributeName
                        value:@2
                        range:NSMakeRange(0, [str length])];

如何改变醒目的颜色?

2 个答案:

答案 0 :(得分:0)

试试这个

NSDictionary *attrs = @{ NSFontAttributeName:[UIFont systemFontOfSize:12.0f],
                         NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle),
                         NSStrikethroughColorAttributeName: [UIColor redColor],
                         NSBackgroundColorAttributeName: [UIColor yellowColor]
                       };

答案 1 :(得分:0)

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Old price"];
NSRange range = NSMakeRange(0, [str length]);
[str addAttribute:NSStrikethroughStyleAttributeName value:@2 range:range];
[str addAttribute:NSStrikethroughColorAttributeName value:[UIColor greenColor] range:range];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:range];