Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISlider thumbTintColor doesn't change on iOS 7 (fine on iOS 6)

I have an app that runs perfectly on iOS 6. I've set a blinking effect to a UISlider's thumb this way:

-(void)startBlinkingSlider{
    isSliderBlinking = YES;
    isSliderTinted = NO;
    [self performSelector:@selector(toggleSliderColor) withObject:nil afterDelay:0.2];
}

-(void)toggleSliderColor{
    if(isSliderBlinking){
        if(isSliderTinted){
            self.effectAmountSlider.thumbTintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
        }else{
            self.effectAmountSlider.thumbTintColor = [UIColor colorWithRed:255 green:0 blue:0 alpha:1];
        }
        isSliderTinted = !isSliderTinted;
        [self performSelector:@selector(toggleSliderColor) withObject:nil afterDelay:0.2];
    }
}

-(void)stopBlinkingSlider{
    isSliderBlinking = NO;
    isSliderTinted = NO;
    self.effectAmountSlider.thumbTintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}

When I call startBlinkingSlider my slider starts blinking red in iOS 6. If I run the same exact app on my iOS 7 device, nothing happens. The slider's thumb retains its original white color. I've set a breakpoint on the line where I set the thumbTintColor. In debugger, here is what I'm getting:

(lldb) po self.effectAmountSlider.thumbTintColor
error: failed to get API lock
(lldb) po self.effectAmountSlider.thumbTintColor
UIDeviceRGBColorSpace 0 0 0 1
(lldb) 

I typed the exact same code and got a weird message in the first one. However, the second result is correct. Then after setting it to red I'm also getting the correct result:

(lldb) po self.effectAmountSlider.thumbTintColor
UIDeviceRGBColorSpace 1 0 0 1

Even though the debugger shows the correct value, I'm getting no visual change in the slider. It's still white, color doesn't change in any way. I've searched Apple's documents here: https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/Controls.html

It doesn't say anything about UISlider's thumbTintColor not working as iOS 6. It should stay working as expected. I've checked the thread and everything is running on the main thread. toggleSliderColor is always on the main thread so it's not a threading issue. Why is my thumb color not working?

Thanks, Can.

like image 743
Can Poyrazoğlu Avatar asked Sep 24 '13 13:09

Can Poyrazoğlu


3 Answers

I discovered a workaround. By first calling the 'setThumbImage:forState:' method, the 'thumbTintColor' property will then take effect.

[self.slider setThumbImage:[UIImage imageNamed:@"Thumb.png"] 
                  forState:UIControlStateNormal];
self.slider.thumbTintColor = [UIColor blackColor];

I tested this on Version 7.0 (463.9.4.2) of iOS Simulator.

like image 146
aaronsti Avatar answered Nov 15 '22 11:11

aaronsti


I just so happened to read the iOS 7 UI Transition Guide again this morning, and tripped on a statement under Slider. If EITHER maximumTrackTineColor OR thumbTintColor are nil, then both properties are ignored. So I tried to set all the tint colors, thumb still white.

I entered a bug report on this - #15277127 - reference it if you enter your own bug. The more bug reports the more likely Apple will fix it soon.

EDIT: Apple duped my bug to another one - this was obviously known a while ago.

like image 34
David H Avatar answered Nov 15 '22 12:11

David H


On basis of @aaronsti's answer I found that the following worked for me. Setting thumb-image to nil had no effect.

  [_slider setThumbImage:[_slider thumbImageForState:UIControlStateNormal] forState:UIControlStateNormal];
_slider.minimumTrackTintColor = minTintColor;
_slider.thumbTintColor = thumbTintColor;
like image 10
dergab Avatar answered Nov 15 '22 11:11

dergab