iPhone:Programming UISlider to position at clicked location

后端 未结 6 478
北荒
北荒 2020-12-09 13:59

How to set the slider to clicked position and get the slider value on the clicked location on UISlider in iPhone programming. i know we can drag the slider to that position

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 14:11

    Here is the part "left as a user exercise":

    - (void) tapped: (UITapGestureRecognizer*) g {
        UISlider* s = (UISlider*)g.view;
        if (s.highlighted)
            return; // tap on thumb, let slider deal with it
        CGPoint pt = [g locationInView: s];
        CGFloat percentage = pt.x / s.bounds.size.width;
        CGFloat delta = percentage * (s.maximumValue - s.minimumValue);
        CGFloat value = s.minimumValue + delta;
        [s setValue:value animated:YES];
    }
    

提交回复
热议问题