Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIslider thumb image doesn't start from the beginning

I am trying to implement a control to show progress of a video and I am using a UISlider with a custom thumb image but the thumb image doesn't start from the beginning and it doesn't go till the end as well.

playerProgress = UISlider(frame: CGRectMake((btnImage.size.width + 2 * VideoViewControllerUX.ControlPadding), 0, (screenRect.size.width - (btnImage.size.width + 3 * VideoViewControllerUX.ControlPadding)), btnImage.size.height))
playerProgress.setThumbImage(UIImage(named: "slider"), forState: UIControlState.Normal)
playerProgress.maximumValue = 100
playerProgress.minimumValue = 0
playerProgress.addTarget(self, action: "playerProgressChanged:", forControlEvents: UIControlEvents.ValueChanged)

Slider Image 1

I am not sure whats going on.

  • Thumb Image:

    Thumb Image

like image 349
sachin irukula Avatar asked Jun 21 '15 18:06

sachin irukula


People also ask

How do I add a slider to my uislider?

Figure 1 shows the terms used to describe the constituent parts of a UISlider object in a left-to-right configuration. To add a slider to your interface: Specify the range of values the slider represents. Optionally, configure the appearance of the slider with appropriate tint colors, and limit images.

What happens when you move the thumb of a slider?

As you move the thumb of a slider, it passes its updated value to any actions attached to it. The appearance of sliders is configurable; you can tint the track and the thumb, and provide images to appear at the ends of the slider. You can add sliders to your interface programmatically or by using Interface Builder.

Can I use custom track and thumb images for my slider?

If you use custom track and thumb images for your slider, remember to set an image for every possible UIControl.State. Any control state that does not have a corresponding custom image assigned to it will display the standard image instead. If you set one custom image, be sure to set them all.

What is a slider in aperture?

A control for selecting a single value from a continuous range of values. As you move the thumb of a slider, it passes its updated value to any actions attached to it. The appearance of sliders is configurable; you can tint the track and the thumb, and provide images to appear at the ends of the slider.


1 Answers

What you're seeing is normal. The slider leaves some extra space at both ends, so that the thumb is at minimum or maximum value when the edge of the thumb is at the end of the slider frame.

Look at these sliders. They have the same horizontal positions and width:

enter image description here

The first slider's thumb is as far to the left as it will go. It doesn't go further left, outside the frame of the track; it stops when its edge hits the the frame of the track. That is zero.

If you don't like where the thumb image is being drawn in relation to the overall track, you'll need to subclass UISlider and implement thumbRectForBounds:trackRect:value:.

like image 87
matt Avatar answered Sep 20 '22 09:09

matt