Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]; 
like image 621
Tom Hamming Avatar asked Mar 10 '14 21:03

Tom Hamming


2 Answers

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.

like image 126
John Estropia Avatar answered Sep 28 '22 08:09

John Estropia


You are correct. This bug has been present since 7.1 first made its appearance in Xcode 5.1 seed 1. I submitted (and resubmitted) the same bug for all 5 seeds of Xcode 5.1, and now on Xcode 5.1. But Apple did not fix it.

Please submit this bug too! You may refer to my bug if you like: 15547259. The more the better! I regard this as serious breakage, because it means that an app that was working fine is now broken (if it uses a progress view with a progressImage).

like image 30
matt Avatar answered Sep 28 '22 07:09

matt