0
我想让UISlider
控制UIImageView
中显示的图片。 Slider min是0,max是50.UISlider控制UIImageView
问题是UIImageView
只对else
和chosenTime = 50
作出反应。 只有在UIImageView
中显示相应的图片。 48和49被忽略,这些情况下显示“else”图片。 任何帮助非常感谢!
下面的代码:
-(IBAction) sliderChanged:(id)sender{
UISlider *slider = (UISlider *) sender;
int prog = (int)(slider.value + 0.5f);
NSString * newText = [[NSString alloc] initWithFormat:@"%d", prog];
sliderLabel.text = newText;
int chosenTime = [newText intValue];
NSLog(@"chosenTime is %i", chosenTime);
//chosenTime is confirmed int value in the NSLOG!!!
if (chosenTime == 1) {
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Pic0001.png"];
clockView.image = [UIImage imageWithContentsOfFile:fullpath];
}
if (chosenTime == 48) {
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Pic0048.png"];
clockView.image = [UIImage imageWithContentsOfFile:fullpath];
}
if (chosenTime == 49) {
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Pic0049.png"];
clockView.image = [UIImage imageWithContentsOfFile:fullpath];
}
if (chosenTime == 50) {
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Pic0050.png"];
clockView.image = [UIImage imageWithContentsOfFile:fullpath];
} else {
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Pic0000.png"];
clockView.image = [UIImage imageWithContentsOfFile:fullpath];
}
}
非常感谢,伟大的学习时刻! – Giel 2012-02-17 09:02:38