Nik's
Nik's

Reputation: 690

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

Upvotes: 8

Views: 19883

Answers (3)

Darshit Shah
Darshit Shah

Reputation: 2382

[[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];

Upvotes: 16

max_
max_

Reputation: 24501

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.

Upvotes: 8

chewy
chewy

Reputation: 8267

Just provide a different size of [email protected] and all we work itself out.

Upvotes: 4

Related Questions