Search code examples
ios-simulatorios7xcode5

iOS 7 Simulator Bug - NSAttributedString does not appear


UPDATE: I have just encountered this issue on an actual iPhone 5 running iOS 7. Will provide more information soon.

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

  • iOS 7 Device: Displays correctly
  • iOS 7 Simulator: Only displays label background
  • iOS 6 Simulator: Displays correctly

Screenshots:

iOS7 Device

iOS 7 Device
iOS7 Simulator
iOS 7 Simulator


Solution

  • 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.