0

我遇到了仅在 iOS7 中出现的 MKNumberBadgeView 问题。在initState中,我有,self.textColor = [UIColor whiteColor];但是当显示 numberBadge 时,文本颜色为黑色。

我对 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]}];,但仍然无法正常工作。

4

1 回答 1

1

对于计算数字字符串的大小,颜色无关紧要。您可能忘记更改另一段实际绘制文本的代码:

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

您必须在那里设置字体颜色。

于 2014-02-05T14:47:14.110 回答