Search code examples
iosxcodeuislider

UISlider maximum track image using minimum track image when slider button crosses approx 60% of max value


I am using UISlider with minimum and maximum images set as follows,

UIImage *stetchLeftTrack = [[UIImage imageNamed:@"Left.png"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:0.0];
[self._timeSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];

UIImage *stetchRightTrack = [[UIImage imageNamed:@"Right.png"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:0.0];
[self._timeSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];

Max image using min image

Everything works as expected untill slider button crosses approx 60% of max value. As you can see in screenshot both min and max slider images got set to min images (Left.png).

Please help Thanks in advance!!!!


Solution

  • In fact I think the base of the problem is a different one, and your solution worked because of that.

    I had the same problem, and when reading the documentation for the track images again I noticed that the stretchable images have to be such that the middle (stretchable) part has to be 1 pixel wide (in retina 2 pixel). My track images were defined as being the complete width of the slider, with left and right caps being 20 pixels, and the middle part something like 230 pixels ...

    When I changed the trackable images to be 41 pixels (20 pixel left part, 1 pixel stretchable middle part, 20 pixels right part) and set the cap insets to UIEdgeInsetsMake(0, 20, 0, 20), it worked all fine.