Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the slider thumb image?

I have to create my own customized slider. I am trying to change the thumb image,background of the slider and in the some test like slide to unlock. I have 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:@"[email protected]"] 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 size of thumb pic is very big.How to reduce the thumb pic size....and how to give the slider background and text.Please help me out

like image 353
Nik's Avatar asked Sep 10 '11 12:09

Nik's


2 Answers

[[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];
like image 51
Darshit Shah Avatar answered Sep 18 '22 06:09

Darshit Shah


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

Also, images that have the appending ending of @2x, mean that they are twice the size of the standard copy. This is for retina displays only, you should not use it in a UIImage on a standard (legacy) device. Try setting the image name to @"sliderThumb.png" instead, as long as you have the legacy copy of the image.

like image 43
max_ Avatar answered Sep 19 '22 06:09

max_