为什么我的NSAttributedString不会出现在UILabel中?

时间:2014-01-16 22:08:28

标签: ios ios7 uilabel nsattributedstring

我有一个动态更新的UILabel。基本上有两个变化轴(单线与双线,以及它是否代表缺失的项目)。我无法显示属性单行(下面代码中的第一个分支)(尽管NSLog显示的是一个结构良好的NSAttributedString)。

if (self.valve.name.length == 0) {
    if (self.valve.isMissing) {
        NSAttributedString *text = [[NSAttributedString alloc] initWithString: self.valve.serialID attributes: [self attributesForMissing]];
        self.nameAndIDLabel.attributedText = text;
        NSLog(@"missing single label = %@", text);
    }
    else {
        self.nameAndIDLabel.text = self.valve.serialID;
    }
}
else {
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: [NSString stringWithFormat: @"%@\n    ", self.valve.name]];
    [text appendAttributedString: [[NSAttributedString alloc] initWithString: self.valve.serialID attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:12.0]}]];
    if (self.valve.isMissing) {
        [text
            addAttributes: [self attributesForMissing]
            range: NSMakeRange(0, text.length)];
        NSLog(@"missing multi label = %@", text);
    }
    self.nameAndIDLabel.attributedText = text;
}

从NSLog发出的缺失输出类型如下:

missing single label = D002614{
    NSColor = "UIDeviceRGBColorSpace 1 0 0 1";
    NSObliqueness = "0.3";
}

显示出来的类型(添加了相同的属性,只是多行)看起来像:

missing multi label = Big Gun Tank SW
    {
    NSColor = "UIDeviceRGBColorSpace 1 0 0 1";
    NSObliqueness = "0.3";
}A005261{
    NSColor = "UIDeviceRGBColorSpace 1 0 0 1";
    NSFont = "<UICTFont: 0x166425f0> font-family: \".HelveticaNeueInterface-M3\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
    NSObliqueness = "0.3";
}

0 个答案:

没有答案