14

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.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • 1
    This feels like a bug to me. I'm just trying to set the tint color for a UISlider as I create it, so much simpler than what you're doing with the blinking, but it keeps coming up white when I run it. I will be eager to hear if this is a confirmed bug or if we are doing something wrong. – GeneralMike Sep 25 '13 at 15:21
  • @GeneralMike if you entered a bug please post it, see my answer below, we an get ours dupped to yours. – David H Oct 21 '13 at 15:01
  • @DavidH: I haven't submitted a bug report yet, I was just speculating that it was a bug. The info from the `iOS 7 UI Transition Guide` you referenced in your answer seems to suggest there is something fishy going on here. I've been temporarily moved to a different project, but when I get back to this I'll file a bug report and dup yours. – GeneralMike Oct 21 '13 at 16:30
  • You probably should switch the answer to aaronsti's since its a real solution to the problem. I've got no problem with that! – David H Nov 12 '14 at 22:54
  • @DavidH You are right, I've switched it. – Can Poyrazoğlu Nov 12 '14 at 22:59

4 Answers4

19

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.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
aaronsti
  • 539
  • 4
  • 5
  • I currently can't test it (the project is currently in an uncompilable state) but does one need Thumb.png to be available as an asset in my project, or does it default it if not specified? – Can Poyrazoğlu Jan 30 '14 at 23:22
  • Yes, Thumb.png must be added to Images.xcassets. If Thumb.png is not found in the assets, it will compile, but the workaround will not work and the slider's thumb will still show as white. It is not necessary to be named Thumb.png but any image name you wish. – aaronsti Feb 03 '14 at 05:36
11

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.

David H
  • 40,852
  • 12
  • 92
  • 138
  • yeah, this really appears to be a bug. I've also entered a bug report too. (i can't see any bugs other than mine though in the bug reporter, so I don't know how to reference) – Can Poyrazoğlu Oct 21 '13 at 14:41
  • @canpoyrazoğlu post your bug number, I'll dup mine to yours – David H Oct 21 '13 at 15:00
  • 15199234. but how do you see others' bugs? – Can Poyrazoğlu Oct 21 '13 at 15:02
  • 2
    @canpoyrazoğlu you cannot see other bugs, but you can just add new information to your bug saying "related bug" or "dup this bug to – David H Oct 21 '13 at 15:03
  • Confirmed, the UISlider was not showing on my iPad Air in iOS 7.1.2 and Xcode 6.1. Thumb Tint was set to Default (clear) in Interface Builder, and when I manually set it to white, the thumb appeared. Min/Max Track Tint had always been Light Gray Color. So this bug has been open just over a year with no resolution by Apple. – Zack Morris Nov 12 '14 at 22:46
  • @ZackMorris I have hundreds of open bugs - stuff like this may never get fixed. It looks like there is a workaround but didn't try it myself (look at aaronsti answer). – David H Nov 12 '14 at 22:53
10

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;
dergab
  • 965
  • 7
  • 16
  • 2
    The first line changes something, but instead of getting the correct `UIColor` on the `thumbImage` I have a color with a gradient and every time I am moving the `UISlider` it changes to the correct color until I don't select it.. – Alex Cio Jun 17 '15 at 09:13
2

So far in Xcode 6.2, iOS 8.2 the problem is still there, and the workaround still works. Swift version:

slider.setThumbImage(slider.thumbImageForState(.Normal), forState:.Normal)
superarts.org
  • 7,009
  • 1
  • 58
  • 44