Clickable UISlider

巧了我就是萌 提交于 2020-01-01 19:15:00

问题


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?


回答1:


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 
}



回答2:


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:).



来源:https://stackoverflow.com/questions/10249510/clickable-uislider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!