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