Clickable UISlider

2019-04-14 09:12发布

I'd like to make my UISlider clickable - to change the value on click to "blank space", e.g. It's set to zero, I click in the middle of the slider and it will "jump" to the middle. Is there any way how to do this?

2条回答
Rolldiameter
2楼-- · 2019-04-14 09:37

I want to propose something similar as jrtc27, but without subclassing: add a UI(Tap)GestureRecognizer to the slider.

UISlider *slider = [[[UISlider alloc] init] autorelease];
//configure slider
UITapGestureRecognizer *tapGestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sliderTapped:)] autorelease];
[slider addGestureRecognizer:tapGestureRecognizer];


- (void)sliderTapped:(UIGestureRecognizer *)gestureRecognizer {
    UISlider *slider = (UISlider *) gestureRecognizer.view;
    //setValue 
}
查看更多
再贱就再见
3楼-- · 2019-04-14 09:45

Subclass it and then alter the -touchesBegan method. If the touch is sufficiently far away, call -setValue:, else call the super implementation (if you want it to always jump, you can just always call -setValue:).

查看更多
登录 后发表回答