-1

有什么方法可以改变 UISlider 中 Range 的 Trackimage,独立于拇指的位置?

它应该如下所示:

滑块

我已经有了没有黄色范围的滑块。我怎样才能达到黄色范围?

4

1 回答 1

2

如果您的部署目标至少是 iOS 6.0,您可以使用UIImageResizingModeTile. 示例代码:

static UIImage *blueYellowStripesImage() {
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(100, 9), YES, 0); {
        [[UIColor blueColor] setFill];
        UIRectFill(CGRectMake(0, 0, 50, 9));
        [[UIColor yellowColor] setFill];
        UIRectFill(CGRectMake(50, 0, 50, 9));
        [[UIColor colorWithWhite:0 alpha:0.4] setFill];
        UIRectFillUsingBlendMode(CGRectMake(0, 5, 100, 4), kCGBlendModeNormal);
    }
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    image = [image resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];
    return image;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIImage *image = blueYellowStripesImage();
    [self.slider setMinimumTrackImage:image forState:UIControlStateNormal];
    [self.slider setMaximumTrackImage:image forState:UIControlStateNormal];
}

结果:

带有平铺图像轨道的滑块

于 2013-04-07T14:02:23.490 回答