Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get UISlider thumb position

How to know UISlider thumb position?
When I press a button I want to add a flag on the current slider thumb position.
How can I acquire the current thumb position so I can add the flag?

This is my synchronization code:

 _positionSlider.value = _mediaplayer.position;

This is how the slider should look like:

look like this image

like image 445
Jinsuk Oh Avatar asked Sep 19 '25 15:09

Jinsuk Oh


1 Answers

Try This, First create UIImageView

@interface ViewController ()
{
    UIImageView *imageView;
}

and write this below code in viewDiload() Function

imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.slider.frame.origin.x, self.slider.frame.origin.y-20, 20, 10)];
imageView.image = [UIImage imageNamed:@"navigateImage.png"];
[self.view addSubview:imageView];

[self.slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];

and add this slider event function

-(void)sliderValueChanged:(UISlider *)slider{

    CGRect trackRect = [self.slider trackRectForBounds:self.slider.bounds];
    CGRect thumbRect = [self.slider thumbRectForBounds:self.slider.bounds
                                             trackRect:trackRect
                                                 value:self.slider.value];

    CGRect r = [imageView frame];
    r.origin.x = thumbRect.origin.x;
    [imageView setFrame:r];

    NSLog(@"%f",thumbRect.origin.x);
 }
like image 75
Subramani Avatar answered Sep 23 '25 10:09

Subramani