Search code examples
iosuislider

How can I fix the track fill image on my UISlider?


I have a custom UISlider image for my track fill but it is going outside the bounds of the track.

Here is the code in my AppDelegate.m

UIImage *minImage = [[UIImage imageNamed:@"slider-track-fill.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
UIImage *maxImage = [UIImage imageNamed:@"slider-track.png"];
UIImage *thumbImage = [UIImage imageNamed:@"slider-cap.png"];


[[UISlider appearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal];
[[UISlider appearance] setMinimumTrackImage:minImage forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateHighlighted];

Slider Image

  • This is how it looks when I load my app

Solution

  • You probably just want to set clips to bounds = YES.

    self.slider.clipsToBounds = YES;