Ser Pounce
Ser Pounce

Reputation: 14527

Disable UISlider from sliding, but still allow it to receive UIControlEventTouchDown

Is there a way to disable a UISlider from sliding, but to get its UIControlEventTouchDown to fire? One way it could be done I believe is to set the slider start value the same as the end value, but I'd like to avoid doing that. Does anyone know a better way?

Upvotes: 1

Views: 2382

Answers (1)

SeanT
SeanT

Reputation: 1791

I would suggest setting userInteractionEnabled = NO for your UISlider, and adding an invisible button to handle the TouchDown

UIButton *btnSlider = [UIButton buttonWithType:UIButtonTypeCustom];
btnSlider.frame = CGRectMake(slider.frame.origin.x, slider.frame.origin.y,         slider.frame.size.width, slider.frame.size.height);
[btnSlider addTarget:self action:@selector(sliderTouched) forControlEvents:UIControlEventTouchDown];
btnSlider.backgroundColor = [UIColor clearColor];

[myView addSubview:btnSlider];

Then based on whatever condition you want to make the slider enabled, you can enable it and disable the button.

Upvotes: 5

Related Questions