Okay I’m trying to use the code. Thanks for posting it.
I built a new project that is a view controller type.
My .h is as follows
Code:
#import <UIKit/UIKit.h>
@interface sliderSwitchViewController : UIViewController {
UISlider *customSlider;
}
- (void)create_Custom_UISlider;
@end
My .m is as follows
Code:
#import "sliderSwitchViewController.h"
@implementation sliderSwitchViewController
- (void)create_Custom_UISlider
{
CGRect frame = CGRectMake(0.0, 0.0, 300, 52.0);
CGRect thumb = CGRectMake(0.0, 0.0, 71.0, 47.0);
customSlider = [[UISlider alloc] initWithFrame:frame];
[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
// in case the parent view draws with a custom color or gradient, use a transparent color
customSlider.backgroundColor = [UIColor clearColor];
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"customTrack.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"customTrack.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[customSlider setThumbImage: [UIImage imageNamed:@"customThumb.png"] forState:UIControlStateNormal];
[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
[customSlider thumbRectForBounds: thumb trackRect: frame value: customSlider.value];
customSlider.minimumValue = 0.0;
customSlider.maximumValue = 100.0;
customSlider.continuous = NO;
customSlider.value = 5.0;
}
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
[self create_Custom_UISlider];
}
I checked and I do have the correctly named images in the resources folder.
It does not work.
My expectation is that it should just place the slider on the screen.
Any thoughts?
Thanks
D