0
我需要創建一個屬性串的一部分:NSAttributedString不顯示文本
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;
,但它的第二部分不是屏幕,只是白色顯示。 當我記錄屬性刺痛時,它顯示完整的字符串。 有什麼問題?
檢查你的標籤或textview的大小,以確保它有足夠的空間爲整個字符串 – Jack
@JackWu,當我顯示文本沒有屬性它工作正常 –