I am trying to make an attributed string with a strikethrough. I can set other attributes such as foreground color and font size but when I try to set a strikethrough through part of the text, that part of the text disappears. Any Idea what might be causing it?
Below is the code. Thanks for looking!
// ...
//Price
NSLog(@"RESULT NUMBER %d", cell.result.resultId);
priceString = (priceString == nil) ? @"$150.00\n$100.00" : priceString;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:priceString];
NSRange linebreak = [priceString rangeOfString:@"\n"];
if (linebreak.location != NSNotFound) {
[attributedString beginEditing];
// RegPrice
NSRange firstLine = NSMakeRange(0, linebreak.location);
// [attributedString addAttribute:NSFontAttributeName
// value:[UIFont boldSystemFontOfSize:11]
// range:firstLine];
[attributedString addAttribute:NSForegroundColorAttributeName
value:[UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1]
range:firstLine];
@try {
[attributedString addAttribute:NSStrikethroughStyleAttributeName
value:@(NSUnderlineStyleSingle)
range:firstLine];
} @catch (NSException *e) {
NSLog(@"ATTRIBUTE EXCEPTION: %@", e);
}
// Sale Price
[attributedString addAttribute:NSFontAttributeName
value:[UIFont boldSystemFontOfSize:14]
range:NSMakeRange(linebreak.location + 1, priceString.length - (linebreak.location + 1))];
[attributedString endEditing];
}
cell.lblPrice.attributedText = attributedString;
return cell;
}