2013-11-03 21 views
0

我遇到了僅在iOS7中顯示的MKNumberBadgeView問題。在initState中,我有self.textColor = [UIColor whiteColor];,但是當顯示numberBadge時,文本顏色是黑色的。MKNumberBadgeView在iOS7中顯示錯誤的文本顏色

我對MKNumberBadgeView類所做的唯一更改是將CGSize numberSize = [numberString sizeWithFont:self.font];更改爲CGSize numberSize = [numberString sizeWithAttributes:@{NSFontAttributeName:self.font}];,因爲sizeWithFont在iOS7中已折舊。

有誰知道爲什麼它不使用我告訴它使用的顏色?

感謝

編輯:
我已經做了一些調查,而且好像sizeWithAttributes是這裏的問題。我用另一個第三方課程創建了一個徽章,並且在sizeWithAttributes中添加了同樣的問題。我試過CGSize numberSize = [numberString sizeWithAttributes:@{NSFontAttributeName:self.font, NSForegroundColorAttributeName:[UIColor whiteColor]}];,但仍然無法正常工作。

回答

1

爲了計算數字串的大小,顏色是無關緊要的。你可能已經忘記了改變另一段代碼,其中的文本實際上被在一個點上得出:

//[numberString drawAtPoint:textPt withFont:self.font]; //this is deprecated 
[numberString drawAtPoint:textPt 
      withAttributes:@{NSFontAttributeName:self.font, 
          NSForegroundColorAttributeName:self.textColor}]; 

必須設置字體顏色有。

+1

我與https://github.com/ckteebe/CustomBadge有同樣的問題。自iOS7發佈以來,Xcode警告不要使用「sizeWithFont」。由於應用程序編譯良好,我一直拒絕採用「withAttributes」。但是隨着iOS8的發展,我決定刪除我的所有警告。而且,一旦我做了,我使用的CustomBadge給了我一個黑色的文字顏色。添加NSForegroundColorAttributeName,爲我解決了一些問題。所以,不知道爲什麼這個問題/(答案)沒有被表決爲正確的。這對我有效。 –

相關問題