UISlider with jagged steps.

I need to implement a slider control as shown below:

The slider will have uneven length steps. When the user slides, the slider slider stops at only one of the steps, which is close to the current range.

But the real problem is the UISlider with points at user points (range) that will be provided initially.

Can anyone help me achieve this functionality.

+4
source share
1 answer

I think you better step back from crippling UISliderin this configuration

, ,

 DKCustomSliderView
 -> UIImageView (subview for slider head)

.

@interface DKCustomSliderView : UIView

-(void)setStopPoints:(NSArray *)stopPoints; //array of NSNumbers between 0-1 which define indents
-(void)setSliderHeadImage:(UIImage *)sliderHeadImage; //image to use as slider head
-(void)setIndentImage:(UIImage *)indentImage; //image to use as indent marker
-(void)setTrackImage:(UIImage *)trackImage; //stretchy image to use on track 

@end

.

-(void)handlePanGesture:(UIPanGestureRecogniser *)pgr {

if(pgr.state == UIGestureRecogniserStateChanged) { 

   //am i near an indent? , if so lock me here and be slightly sticky.

}
}

draw rect DKCustomSliderView .

-(void)drawRect:(CGRect)dirtyRect {

CGRect bounds = self.bounds;

// 1. draw track across width

for(NSNumber *marker in self.stopPoints) {

//draw a instance of self.indentImage at ([marker floatValue]/bounds.size.width)

}

}
+1

Source: https://habr.com/ru/post/1532278/


All Articles