I have a UILabel that I update dynamically. There are basically two axes of variation (single vs double line, and whether it represents a missing item). I cannot get the attributed single line (the first branch in the code below) to show up (though the NSLog shows what looks like a well formed 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;
}
The type of output that comes out from the NSLog for the missing one looks like:
missing single label = D002614{
NSColor = "UIDeviceRGBColorSpace 1 0 0 1";
NSObliqueness = "0.3";
}
The type that shows up for the one that does show up (same attributes added, just multi line) looks like:
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";
}