我想将图像放入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图片。
答案 0 :(得分:7)
这是ios7的变化。现在UISegmentedControl
使用self的色调颜色来改变图像的色调,因此您必须以原始模式渲染图像。
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];
答案 1 :(得分:-1)
如果需要在UISegmentedControl中将图像设置为Item
- (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment