UISlider custom image stuck

Why is the slider image inserted in the place where it was downloaded?

This is my code:

for (UISlider *slider in volumeSlider.subviews) {
    if ([slider isKindOfClass:[UISlider class]]) {
        [slider setMinimumTrackImage:[[UIImage imageNamed:@"sliderMax.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal ];
        [slider setMaximumTrackImage:[[UIImage imageNamed:@"sliderMin.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal ];
        [slider setThumbImage:[UIImage imageNamed:@"thumbSlider.png"] forState:UIControlStateNormal];
    }
}

enter image description here

+4
source share
2 answers

Ok, that’s what I found! To work around this problem, swap the sliders at the very top of your viewdidload method (or, essentially, before any other manipulations with your slider).

After that, I found that my custom slider behaved as it should! (tested on iOS 7.0.2).

+1
source

I have the same situation as at the right end of the track. It was unpleasant. But I solved the problem with this code:

- (CGRect)trackRectForBounds:(CGRect)bounds {
    return (CGRect) {0,0, bounds.size.width, bounds.size.height};
}

(My custom track is the same size as the slider)

0

All Articles