Lack of documentation on UISlider

April 19, 2009 § 3 Comments

UISlider is poorly documented even through it is a commonly used UI Control. I am sharing my experience here.

In this CGRectMake(x, y, slider’s width, y), x and y gives the slider’s starting point on x and y coordinates considering the left side of slider is the default starting point.

Slider’s width determines the UISlide’s length. By default there is no size control on slider’s control image. The last no. will add additional y coordinate values.

You can customize the image at minimum and maximum end of slider by using setMinimumValueImage: and setMaximumValueImage: methods . Adding the images will cause a reduction in the slider’s length. Use smaller images for mini and maxi position if you have restricted area for slider. Use setBackgroundColor: method to set the background color or make a clear background.

// Slider
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 100, 200, 0)];
[slider setMinimumValueImage:[UIImage imageNamed:@”icon_player_min.png”]];
[slider setMaximumValueImage:[UIImage imageNamed:@”icon_player_max.png”]];
[slider setBackgroundColor:[UIColor clearColor]];
slider.minimumValue = 0.0;
slider.maximumValue = 100.0;
slider.tag = 1;
slider.value = 50.0;
slider.continuous = YES;
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
[slider release];

Add this method to track slider’s value.

– (void)sliderAction:(id)sender {
UISlider *audioSlider = (UISlider *)sender;
float value = audioSlider.value;
NSLog(@”Audio Volume: %f”, value);
// add the code

If you are up to the challenge to customize the entire UISlider including the slider’s bar, you would have to create your images.

UIImage *sliderLeftTrack = [[UIImage imageNamed:@”left_slide.png”]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *sliderRightTrack = [[UIImage imageNamed:@”right_slide.png”]
stretchableImageWithRightCapWidth:10.0 topCapHeight:0.0];[customSlider setThumbImage: [UIImage imageNamed:@”control.png”] forState:UIControlStateNormal];
[slider setMinimumTrackImage:sliderLeftTrack forState:UIControlStateNormal];
slider setMaximumTrackImage:sliderRightTrack forState:UIControlStateNormal];


§ 3 Responses to Lack of documentation on UISlider

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

What’s this?

You are currently reading Lack of documentation on UISlider at Web Builders.


%d bloggers like this: