How to change the image of the slider?

I need to create my own slider. I am trying to change the thumb image, the background of the slider and in some kind of test, for example slide, to unlock. I tried like this, but its not working

CGRect frame = CGRectMake(0.0, 219.0, 323.0, 20.0); UISlider *myslider = [[UISlider alloc] initWithFrame:frame]; [myslider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged]; [myslider setBackgroundColor:[UIColor clearColor]]; [myslider setThumbImage: [UIImage imageNamed:@" sliderThumb@2x.png "] forState:UIControlStateNormal]; myslider.minimumValue = 0.0; myslider.maximumValue = 50.0; myslider.continuous = YES; myslider.value = 15.0; [self.view addSubview:myslider]; 

But in this, the large pic size is very large. How to reduce thumb size ... and how to give slider background and text. Please help me

+7
source share
3 answers

To set the background color of the slider, I would suggest that you can set the backgroundColor property to [UIColor colorWithPatternImage:[UIImage imageNamed:@"slider background"]];

In addition, images with the end of @2x added mean that they are two times larger than the standard copy. This is only for retina displays, you should not use it in UIImage on a standard (obsolete) device. Try changing the name of the image to @"sliderThumb.png" if you have an outdated copy of the image.

+7
source
 [[UISlider appearance] setThumbImage:[UIImage imageNamed:@"ball.png"] forState:UIControlStateNormal]; [slider setMinimumTrackImage:[[UIImage imageNamed:@"volume_slider_oragne.png"] stretchableImageWithLeftCapWidth:0.3 topCapHeight:0.0] forState:UIControlStateNormal]; [slider setMaximumTrackImage:[[UIImage imageNamed:@"volume_strap_gry.png"] stretchableImageWithLeftCapWidth:0.3 topCapHeight:0.0] forState:UIControlStateNormal]; 
+13
source

Just specify a different sliderThumb@2x.png size and everything we can do.

+3
source

All Articles