I have a customized UISlider which has its track image disappear sometimes. It happens at random and when its parent view controller is pushed to visible (I never see it actually disappear).
Here is my code for setting up the UISlider:
timeSlider = [[UISlider alloc] initWithFrame:CGRectMake(55, 8, 210, 23)];
timeSlider.backgroundColor = [UIColor clearColor];
UIImage *blutrackImg = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluetrack" ofType:@"png"]];
UIImage *whitetrackImg = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"whitetrack" ofType:@"png"]];
//UIEdgeInsetsMake(top,left,bottom,right)
UIImage *stetchLeftTrack = [blutrackImg stretchableImageWithLeftCapWidth:9.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [whitetrackImg stretchableImageWithLeftCapWidth:9.0 topCapHeight:0.0];
[timeSlider setThumbImage: [UIImage imageNamed:@"whiteslide2.png"] forState:UIControlStateNormal];
[timeSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[timeSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
timeSlider.continuous = NO;
[timeSlider addTarget:self action:@selector(trackTime:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:timeSlider];
I am building on iOS 5.0. Has anyone ever ran into such a thing?
SOLUTION FOUND: I believe this problem was caused by the following mistake:
I had a timer which was setting the value of the slider using the slider.value property instead of the [slider setValue: animated:] method. I was also not sanity checking the value being set.
Addressing those to issues has solved the problem.
I second the "Answer" and want to esp. point out the bit about sanity checking the values. I don't think it matters if you use slider.value or [slider setValue], setting it to a NaN means the background in iOS5 disappears.
NB: Getting a NaN as a returned value something that can happen often if you're using the iPod library and asking for current position.
i had the same problem, it was caused by duplication resources. Check it in Build Phases, if it is rename recources in xCode.
NaN was my issue too, but it's worse than I expected... even setting the UISlider to NAN once, on iOS5, seems to forever break that instance of the control was was surprising and took a little time to track down.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With