I think I have found a bug in the iOS 7 Simulator where a NSAttributedString does not appear. It would be great if someone else could test this to confirm it is a bug, then I will file a bug with Apple.
The problem appears to be the combination of using NSUnderlineStyleAttributeName and NSParagraphStyleAttributeName for NSAttributedString.
Here are the steps to reproduce:
1) In Xcode 5 create a new 'Single View Application'. Call it whatever.
2) In ViewController.m, replace the viewDidLoad method with:
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableParagraphStyle* paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSTextAlignmentCenter;
NSAttributedString* attrStr = [[NSAttributedString alloc] initWithString:@"Lorem ipsum dolor sit" attributes:
@{NSUnderlineStyleAttributeName:@1,
NSParagraphStyleAttributeName:paragraph}];
UILabel* myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 0, 0)];
myLabel.backgroundColor = [UIColor greenColor];
myLabel.attributedText = attrStr;
[myLabel sizeToFit];
[self.view addSubview:myLabel];
}
3) Run on an iOS 7 device and then run it again in the iOS 7 simulator.
4) Lastly, set the deployment target to iOS 6 and run it on the iOS 6 simulator.
The results should be the following
Screenshots:
iOS7 Device
iOS7 Simulator
It appears this is not a Simulator bug, but an iOS 7 bug as I have been able to reproduce it on a device now. I have created a new question for it here: iOS 7 BUG - NSAttributedString does not appear
The bug appears to be the combination of using NSUnderlineStyleAttributeName & NSParagraphStyleAttributeName as attributes for a NSAttributedString.
Following line causing the issue.
NSParagraphStyleAttributeName:paragraph
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With