1

我需要在 iOs 7 上的分段控制器中显示图像。问题是图像无法缩放以填充段(它只是位于中间)。

这是代码:

self.segmentedController.tintColor = [UIColor clearColor];

UIImage *imageSegmentedLOff;
UIImage *imageSegmentedMOn;

if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {
    imageSegmentedLOff = [[UIImage imageNamed:IMAGE_SEGMENTED_L_OFF] resizableImageWithCapInsets:UIEdgeInsetsMake(2.0, 2.0, 2.0, 2.0)];
    imageSegmentedLOff = [imageSegmentedLOff imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    imageSegmentedMOn = [[UIImage imageNamed:IMAGE_SEGMENTED_M_ON] resizableImageWithCapInsets:UIEdgeInsetsMake(2.0, 2.0, 2.0, 2.0)];
    imageSegmentedMOn = [imageSegmentedMOn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  } else {
    imageSegmentedLOff = [UIImage imageNamed:IMAGE_SEGMENTED_L_OFF];
    imageSegmentedMOn = [UIImage imageNamed:IMAGE_SEGMENTED_M_ON];
}

[self.segmentedController setImage:imageSegmentedLOff forSegmentAtIndex:0];
[self.segmentedController setImage:imageSegmentedMOn forSegmentAtIndex:1];

有任何想法吗?

4

0 回答 0