Search code examples
iosiphoneios7uiimageuislider

iOS 7 If Statement to assign UIImage not working


So I'm in the middle of updating our app to be more iOS 7 ready, and one part of the code that was working previously isn't working any more. In this section I'm using a UISlider as a vertical bar graph, and I have my own PNG's that I want to use for the Max and Min Track images but for the Min Track Image I have an if statement that will pick either a green or red image, but for some reason the UIImage is always coming back as null. Here's a snippet from the section (basically just the part with the images) and I don't know what's causing it to not work. When I remove the If statement and just assign either the red or green image it works fine so I know it's something that needs to be changed I just can't seem to find what needs to be changed.

//Setup Images for Slider/Bar Graph
UIImage *whiteImage = [[UIImage imageNamed:@"whiteButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
UIImage *greenImage = [[UIImage imageNamed:@"greenButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
UIImage *redImage = [[UIImage imageNamed:@"redButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
UIImage *blankButton = [UIImage imageNamed:@"blankButton"];
//Check to see which image should be used for the Min Track
UIImage *trackImage = [UIImage new];
if ([self.foundMTDValue doubleValue] >= currentDayGoal) 
{
     trackImage = greenImage;
}
else {
     trackImage = redImage;
}
 NSLog(@"track image = %@", trackImage);
        //Setup Main Slider
[sliderCell.mainSlider setMinimumTrackImage:trackImage forState:UIControlStateNormal];
[sliderCell.mainSlider setMaximumTrackImage:whiteImage forState:UIControlStateNormal];
[sliderCell.mainSlider setThumbImage:blankButton forState:UIControlStateNormal];
[sliderCell.mainSlider setMinimumValue:0];
[sliderCell.mainSlider setMaximumValue:mtdGoal];
[sliderCell.mainSlider setValue:[self.foundMTDValue doubleValue]];

Solution

  • Nevermind, I found the issue. Looks like the image name in my asset catalog was messed up so that's why the red image was always coming back null. Fixed it and everything's working now.