使用带有iOS 7的NSForegroundColorAttributeName时,带有表情符号的字符串会被取代

时间:2013-10-13 11:21:51

标签: ios7 nsmutableattributedstring

当我使用带有表情符号的字符串的NSForegroundColorAttributeName时,字符串会垂直移位。

以下是一个例子:

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 21)];
label1.text = @"@Hashtag";
//label1.backgroundColor = [UIColor redColor];
label1.numberOfLines = 0;
label1.shadowColor = [UIColor colorWithWhite:1 alpha:0.5];
label1.shadowOffset = CGSizeMake(1,1);
[label1 sizeToFit];
[self.view addSubview:label1];

NSString *comment = @"@Hashtag ";

NSMutableAttributedString *commentAttributedString = [[NSMutableAttributedString alloc]  initWithString:comment];
[commentAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor  darkGrayColor] range:NSMakeRange(0, comment.length)];
[commentAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 8)];

UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 21)];
label2.attributedText = commentAttributedString;
label2.numberOfLines = 0;
label2.shadowColor = [UIColor colorWithWhite:1 alpha:0.5];
label2.shadowOffset = CGSizeMake(1,1);
[label2 sizeToFit];
[self.view addSubview:label2];

我得到以下结果:

绿色标签被取代。这只适用于iOS 7,iOS 6一切正常。

有人知道为什么会这样吗?

亲切的问候

阿诺

0 个答案:

没有答案