iPhone – Adding UISlider to UIToolbar

If you want to add a UISlider to a UIToolbar, you have to wrap the UISlider as a UIBarButtomItem. The following code should help.

	// Initialize
	aSlider = [[UISlider alloc] init];
	UIBarButtonItem *sliderAsToolbarItem = [[UIBarButtonItem alloc] initWithCustomView:aSlider];
	// Set the width of aSlider
	[sliderAsToolbarItem setWidth:250.0];

	// Add the items to the toolbar
	[toolbar setItems:[NSArray arrayWithObjects:sliderAsToolbarItem, nil]];

 

Done =)

4 thoughts on “iPhone – Adding UISlider to UIToolbar”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.