Search code examples
iosios7uiprogressview

UIProgressView custom track and progress images in iOS 7.1


iOS 7.1 seems to have broken the custom image properties in UIProgressView. Code that used to successfully customize progress views now yields the default appearance.

I set up a sample project that does this in viewDidLoad:

self.progressView.frame = CGRectMake(self.progressView.frame.origin.x, self.progressView.frame.origin.y, self.progressView.frame.size.width, 9);
UIImage *img = [UIImage imageNamed:@"progress_bar_fill.png"];
img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
self.progressView.progressImage = img;

img = [UIImage imageNamed:@"progress_bar_empty.png"];
img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
self.progressView.trackImage = img;

I still get the default appearance. I've stepped through and verified that img is non-nil as expected. What's going on?

UPDATE: There is an OpenRadar for this, and I've also filed a radar of my own complete with a sample project.

UPDATE 2: As noted by Axy below, you have to add this to get the JEProgressView to work correctly:

_progressBar.tintColor = [UIColor clearColor];

Solution

  • This is very annoying. I didn't find a way to fix this without subclassing UIProgressView.

    Anyway here's how I fixed this: https://gist.github.com/JohnEstropia/9482567

    You will have to change occurrences of UIProgressView to JEProgressView, including those in NIBs and storyboards.

    Basically, you'd need to force assigning the images directly to the UIProgressView's children UIImageViews.

    The subclass is needed to override layoutSubviews, where you adjust the heights of the imageViews according to the image sizes.