我有一个NSString
它本身包含 unicode 字符。
前任:
It's blank.\u000e test \u000f
的NSString
长度是19
。
在这里,\u000e
和\u000f
是 Unicode 字符。
我将上述内容转换NSString
为 anNSMutableAttributedString
并应用了一些 font-weight 属性。然后,我记录NSMutableAttributedString
并获得以下输出。
我的示例代码:
NSString *contAtRng = @"It's blank.\u000e test \u000f";
NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] initWithString:contAtRng];
NSMutableDictionary *attrs = [NSMutableDictionary new];
[attrs setObject:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10] forKey:NSFontAttributeName];
[attrText setAttributes:attrs range:NSMakerange(0,contAtRng.length)];
NSLog(@"String : %@",attrText);
输出:
It's blank. test {
NSFont = "<UICTFont: 0x16d22250> font-family: \"Helvetica Neue\"; font-weight: bold; font-style: normal; font-size: 10.00pt";}
现在的NSMutableAttributedString
长度是17
。
结果,缺少 Unicode 字符。我不知道我的代码做错了什么。