我需要创建一个属性字符串:
NSString *forecastLow = [forecast valueForKey: @"low"];
NSString *forecastHigh = [forecast valueForKey: @"high"];
self.forecastLabel.font = [UIFont fontWithName: @"PT Sans" size: 13];
NSMutableAttributedString *attriburedString = [[NSMutableAttributedString alloc] initWithString: [NSString stringWithFormat: @"%@/%@\u00B0", forecastLow, forecastHigh]];
[attriburedString addAttribute: NSForegroundColorAttributeName
value: [UIColor colorWithRed: 0.f green: 0.f blue: 0.f alpha: 1.f]
range: NSMakeRange(0, [forecastLow length])];
attriburedString addAttribute: NSForegroundColorAttributeName
value: [UIColor colorWithRed: 10 green: 10 blue: 10 alpha: 1]
range: NSMakeRange([forecastLow length], [attriburedString length] - 1)];
self.forecastLabel.attributedText = attriburedString;
但它的第二部分没有显示在屏幕上,只是白色。当我记录属性刺痛时,它会显示完整的字符串。有什么问题?