11

I noticed that UISlider in iOS7 behaves differently than it did in iOS 6 and iOS 5:

Say you have a slider with min=0 and max=10, current value is 0. When you first touch the "knob", a valueChanged message is sent with slider.value=0.269 (instead of the expected 0) and the knob moves towards the middle. Generally, touching the slider moves it towards the middle value (5 in this example), the farther out from the middle it currently is, the more it moves.

All this did not happen in iOS6, and I'd like to restore the old behaviour, but have no idea how to achieve this.

Gereon
  • 17,258
  • 4
  • 42
  • 73

3 Answers3

16

Apple has not commented on my bug report yet, but I've found a solution more or less by accident: installing a custom image for the knob restores the behaviour from iOS 6:

[self.slider setThumbImage:[UIImage imageNamed:@"knob"] forState:UIControlStateNormal];
Gereon
  • 17,258
  • 4
  • 42
  • 73
  • What if I want to use default thumb image? Is there any fix? Any response from Apple? – user1561346 May 01 '15 at 23:43
  • Unfortunately, Apple hasn't responded to my bug report yet (it's 15743419 if you want to dupe it), and I'm not aware of any other fix or workaround. Sorry! – Gereon May 03 '15 at 09:46
  • This is getting even stranger. If I set a thumb image for `UIControlState.Normal` it starts to move away from the center on every touch which is the exact opposite behaviour? In `.Selected` it seems to work properly without moving anywhere. – Aleksi Sjöberg Sep 22 '15 at 05:49
  • This is still an issue in iOS 9.2.1. Can be reproduced in the iPhone Settings app when using the brightness slider. Duped your Radar. – Petter Feb 23 '16 at 09:31
  • This is still an issue in iOS 11.2.1. Can be reproduced in the iPhone Settings app when using the brightness slider. – aaronsti Jan 12 '18 at 00:46
5

On iOS 9 you need to set for .Normal, .Selected and .Highlighted states to work. I found this after 5h of struggling. Way to go Apple!

[_sliderView setThumbImage:[UIImage imageNamed:@"knob"] forState:UIControlStateNormal];
[_sliderView setThumbImage:[UIImage imageNamed:@"knob"] forState:UIControlStateSelected];
[_sliderView setThumbImage:[UIImage imageNamed:@"knob"] forState:UIControlStateHighlighted];
Josip B.
  • 2,434
  • 1
  • 25
  • 30
2

I tested it and can confirm the described behavior.

Interestingly, when the app is built using the iOS 6 SDK but the device/simulator still runs iOS 7 (in compatibility mode) the bug does not occur. So it seems that it's connected to the new look.

File a bug.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200