4

Here I need to rounded uslider but when i try to set images it shows rectangled image,

I need like this Imageenter image description here

Here My coding

UIImage *volumeBackgroundImage = [[UIImage imageNamed:@"l2.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(9, 5, 7, 5)];
    [self.audioSlider setMinimumTrackImage:[[UIImage imageNamed:@"l1.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(9, 5, 7, 5)]
                               forState:UIControlStateNormal];
    [self.audioSlider setMaximumTrackImage:volumeBackgroundImage
                               forState:UIControlStateNormal];
    [self.audioSlider setThumbImage:[UIImage imageNamed:@"sliderhandle.png"]
                        forState:UIControlStateNormal];

Could anybody help to achieve this

Jano
  • 62,815
  • 21
  • 164
  • 192
dineshprasanna
  • 1,284
  • 4
  • 20
  • 37

3 Answers3

5

You need to have images with round corners. For example: enter image description here

Then simply use this image like this:

[_slider setMinimumTrackImage:[[UIImage imageNamed:@"black_dot.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 12, 12)]
    forState:UIControlStateNormal];

[_slider setMaximumTrackImage:[[UIImage imageNamed:@"blue_dot.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 12, 12) 
    forState:UIControlStateNormal];

(where black_dot.png is example image, and blue_dot.png would be the same but in blue color)

(If image is pixelated - then You need to get this image twice as big - retina image - black_dot@2x.png)

(Or in case You actually need smaller image than given example, then just rename this image as black_dot@2x.png, and instead of : UIEdgeInsetsMake(12, 12, 12, 12) use: UIEdgeInsetsMake(6, 6, 6, 6))

See more info here:https://stackoverflow.com/a/8656216/894671

Community
  • 1
  • 1
Guntis Treulands
  • 4,764
  • 2
  • 50
  • 72
1

You can try to draw the image of the size required, rather than adding a image which might cause distortion.

Slider distortion solution

Pooja Kamath
  • 1,290
  • 1
  • 10
  • 17
0

I think this occurs because the round end is generated by the UISlider natively. It assumes that the thumb image will cover the end at extreme positions so it will not redraw it.

One solution could be to take care of the rounding at the end yourself:

self.audioSlider.layer.cornerRadius = 5.0;

Experiment with this value and it should work.

Alternatively, you could make sure your images have rounded ends.

Mundi
  • 79,884
  • 17
  • 117
  • 140