MappleDev
MappleDev

Reputation: 453

Custom UISlider Image Stuck

Why does the slider image stick at the point where it was loaded?

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

Upvotes: 4

Views: 1669

Answers (2)

Alex Nazarov
Alex Nazarov

Reputation: 1218

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

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

(My custom track has the same size as slider view)

Upvotes: 0

Riz Khan
Riz Khan

Reputation: 21

Ok here is what I have found! To get around this issue skin your sliders at the very top of your viewdidload method (or essentially before any other manipulation to your slider).

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

Upvotes: 1

Related Questions