iOS 7:Segmentedcontrol不会显示图像颜色

时间:2013-11-11 14:15:43

标签: ios xcode ios7 xcode5 uisegmentedcontrol

我有这个分段控制,但它不会正确显示我的图像:( 圆圈需要是绿色,黄色和红色。 查看截图以了解:D

如果你知道我做错了什么或错过了请回答:) 谢谢!

这适用于iOS 6 ..

The green colour for the green circle is chose

It just display blue circles?

1 个答案:

答案 0 :(得分:5)

在iOS 7下,图像用作蒙版,然后使用标准iOS 7着色机制着色(非常类似于UIToolbar图标)。

我不知道如何在Interface Builder中进行设置,但代码中的解决方案是将每个图像设置为原始格式,如下所示:

UIImage *correctImage = [[UIImage imageNamed:@"someName"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

然后将此图像与分段控件一起使用。

一种选择是更新viewDidLoad方法中的分段控件,如下所示:

NSUInteger count = control.numberOfSegments;
for (NSUInteger i = 0; i < count; i++) {
    UIImage *original = [control imageForSegmentAtIndex:i];
    UIImage *fixed = [original imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [control setImage:fixed forSegmentAtIndex:i];
}