Search code examples
iosobjective-cuser-interfaceuislider

UISlider drag behaving strangely in iOS


I have a strange problem with a UISlider I add to my view programmatically. I believe the issue was introduced with IOS7.

I am not using any custom images.

As the images below show, the track only appears when I begin to move it from my maximum value to my minimum value, it then disappears when I move it back.

enter image description here enter image description here enter image description here

This is the code I use to create the slider.

_brightnessSlider = [[UISlider alloc] initWithFrame:CGRectMake(size.width * .45,
                                                               size.height * .78,
                                                               size.width * .4,
                                                               size.height * .1)];

[_brightnessSlider setBackgroundColor:[UIColor clearColor]];
_brightnessSlider.minimumValue = 0.0;
_brightnessSlider.maximumValue = 1.0;
_brightnessSlider.continuous = YES;
_brightnessSlider.value = 1.0;
[_brightnessSlider addTarget:self action:@selector(changeBrightness:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:_brightnessSlider];

What could be causing this strange behaviour?


Solution

  • There is nothing wrong in the code.. The issue is "Min Track Tint colour". Your View background colour might be matching with MInTrackTintColor.

    Use this:

    [_brightnessSlider setMinimumTrackTintColor: [UIColor blueColor]];
    

    Let me know if it does not solve your issue...