Ios simulator iOS 7模拟器错误-未显示NSAttributedString 更新:我刚刚在运行iOS7的iPhone5上遇到了这个问题。将很快提供更多信息。

Ios simulator iOS 7模拟器错误-未显示NSAttributedString 更新:我刚刚在运行iOS7的iPhone5上遇到了这个问题。将很快提供更多信息。,ios-simulator,ios7,xcode5,Ios Simulator,Ios7,Xcode5,我想我在iOS 7模拟器中发现了一个错误,其中没有出现NSAttribute字符串。如果其他人可以测试这个程序来确认它是一个bug,那就太好了,然后我会向苹果公司提交一个bug 问题似乎是NSAttributeString同时使用NSUnderlineStyleAttributeName和NSParagraphStyleAttributeName 以下是复制的步骤: 1) 在Xcode 5中创建一个新的“单视图应用程序”。管它叫什么 2) 在ViewController.m中,将viewDidL

我想我在iOS 7模拟器中发现了一个错误,其中没有出现NSAttribute字符串。如果其他人可以测试这个程序来确认它是一个bug,那就太好了,然后我会向苹果公司提交一个bug

问题似乎是NSAttributeString同时使用NSUnderlineStyleAttributeName和NSParagraphStyleAttributeName

以下是复制的步骤:

1) 在Xcode 5中创建一个新的“单视图应用程序”。管它叫什么

2) 在ViewController.m中,将viewDidLoad方法替换为:

- (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) 在iOS 7设备上运行,然后在iOS 7模拟器中再次运行

4) 最后,将部署目标设置为iOS 6,并在iOS 6模拟器上运行它

结果如下

  • iOS 7设备:正确显示
  • iOS 7模拟器:仅显示标签背景
  • iOS 6模拟器:正确显示
屏幕截图:

iOS7设备


iOS7模拟器

以下是导致问题的行


NSParagraphStyleAttributeName:段落

这似乎不是一个模拟器错误,而是一个iOS 7错误,因为我现在已经能够在设备上重现它了。我在这里提出了一个新问题:

该错误似乎是将NSUnderlineStyleAttributeName和NSParagraphStyleAttributeName作为NSAttributedString的属性的组合。

这对我很有效

//Swift
let underlineAttribute = [NSUnderlineStyleAttributeName:NSNumber(int: 1)];
lblMessage.attributedText = NSAttributedString(string: "Your text", attributes: underlineAttribute)
//Am33t

谢谢,你帮我节省了很多时间。是的,我也遇到了这个。我花了很多时间在谷歌上搜索,却没有找到答案。真糟糕。现在看看我的解决方法: