2014-07-24 42 views
0

是試圖修復iOS應用程序的一些警告和改變此更新:顏色drawInRect的:withAttributes:

[[self text] drawInRect:rect withFont:[UIFont systemFontOfSize:kFontSize]]; 
[[UIColor whiteColor] set]; 

這樣:

[[self text] drawInRect:rect withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kFontSize]}]; 
[[UIColor whiteColor] set]; 

然而現在的顏色文字是黑色的...我該如何解決這個問題?

+0

順便說一句 - 舊的方式不會工作,因爲你需要在繪製文本之前設置顏色。 – rmaddy

+0

這是工作之前,不知道爲什麼...它是爲iOS 4.3 – user906357

回答

2

您需要的顏色添加到屬性:

NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:kFontSize], NSForegroundColorAttributeName : [UIColor whiteColor] }; 
[[self text] drawInRect:rect withAttributes:attributes]; 

無需設置顏色使用這種方法的老路上。

+0

完美的作品,謝謝! – user906357