UISegmentedControl 中的图像是蓝色的?

Image in UISegmentedControl is blue?

我想将图片放入 UISegmentedControl 项,但我的图片是蓝色的,无法正常显示? 这是我的代码:

NSArray *segments = [[NSArray alloc] initWithObjects:
                         [UIImage imageNamed:@"iphone1.png"],
                         @"iPad",
                         @"iPod",
                         @"iMac", nil];
    self.mySegmentedControl = [[UISegmentedControl alloc] initWithItems:segments];
    CGRect segmentedFrame = self.mySegmentedControl.frame;
    segmentedFrame.size.height = 64.0f;
    segmentedFrame.size.width = 300.0f;
    self.mySegmentedControl.frame = segmentedFrame;
    self.mySegmentedControl.center = self.view.center;
    [self.view addSubview:self.mySegmentedControl]; 

第一段是 iphone 图片。

这是一个 ios7 的变化。现在UISegmentedControl使用自己的tint color来改变图像的色调,所以你必须以原始模式渲染图像。

UIImage* iPhoneImage = [UIImage imageNamed:@"iphone1.png"];
if (//Device is iOS7 or higher) {
    iPhoneImage = [iPhoneImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

NSArray *segments = [[NSArray alloc] initWithObjects:
                     iPhoneImage,
                     @"iPad",
                     @"iPod",
                     @"iMac", nil];

如果需要在UISegmentedControl中给Item设置image

- (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment