UISlider won't display
- by user290295
I have been having a lot of difficulty adding custom track images to a
UISlider. Whenever I do this, whether to a nib created UISlider or a
hand programmed UISlider the slider refuses to display. Also, I even
commented the track image code out below and the UISlider still
refuses to display. There are other nib created sliders in the
controlView that display and function fine.
if (![self loadView:keyboardControlView intoSuperview:controlView withNib:@"KeyboardControl"]) {
NSLog(@"Could not load controlView from nib into synthControlView");
}
// nibSlider is an outlet to a UISlider in the above loaded nib file
CGRect sliderFrame = nibSlider.frame;
float sliderMinimum = nibSlider.minimumValue;
float sliderMaximum = nibSlider.maximumValue;
float sliderValue = nibSlider.value;
// remove from superview, implicitly releasing UISlider
[nibSlider removeFromSuperview];
// reuse pointer to allocate new UISlider using rect obtained from nib
nibSlider = [[UISlider alloc] initWithFrame:sliderFrame];
nibSlider.backgroundColor = [UIColor clearColor];
nibSlider.minimumValue = sliderMinimum;
nibSlider.maximumValue = sliderMaximum;
nibSlider.continuous = YES;
nibSlider.value = sliderValue;
//[nibSlider setMinimumTrackImage:[[UIImage imageNamed:@"violetslider.png"]
//stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0] forState:UIControlStateNormal];
//
//[nibSlider setMaximumTrackImage:[[UIImage imageNamed:@"violetslider.png"]
// stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0] forState:UIControlStateNormal];
[nibSlider addTarget:delegate action:@selector(sliderUpdate:) forControlEvents:UIControlEventValueChanged];
[controlView addSubview:nibSlider];
// do not release here as slider will need to remain cached. push onto a release stack.
[nibSlider setNeedsDisplay];