iOS 7.1中的UIProgressView自定义跟踪和进度图像 [英] UIProgressView custom track and progress images in iOS 7.1
问题描述
iOS 7.1似乎打破了 UIProgressView
中的自定义图像属性。用于成功自定义进度视图的代码现在产生默认外观。
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.
我设置了一个示例项目,在 viewDidLoad $ c中执行此操作$ c>:
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;
我仍然得到默认外观。我已逐步完成并验证 img
是否符合预期。发生了什么?
I still get the default appearance. I've stepped through and verified that img
is non-nil as expected. What's going on?
更新:有一个 OpenRadar 为此,我还提交了一份我自己的雷达以及一个示例项目。
UPDATE: There is an OpenRadar for this, and I've also filed a radar of my own complete with a sample project.
更新2:如前所述下面的Axy,你必须添加它以使JEProgressView正常工作:
UPDATE 2: As noted by Axy below, you have to add this to get the JEProgressView to work correctly:
_progressBar.tintColor = [UIColor clearColor];
推荐答案
这很烦人。我没有找到办法解决这个问题而没有继承 UIProgressView
。
This is very annoying. I didn't find a way to fix this without subclassing UIProgressView
.
无论如何这里是我修复这个的方法:< a href =https://gist.github.com/JohnEstropia/9482567> https://gist.github.com/JohnEstropia/9482567
Anyway here's how I fixed this: https://gist.github.com/JohnEstropia/9482567
您必须将 UIProgressView
的出现更改为 JEProgressView
,包括NIB和故事板中的那些。
You will have to change occurrences of UIProgressView
to JEProgressView
, including those in NIBs and storyboards.
基本上,您需要强制将图像直接分配给 UIProgressView
的子项 UIImageView
s。
Basically, you'd need to force assigning the images directly to the UIProgressView
's children UIImageView
s.
需要子类来覆盖 layoutSubviews
,您可以在其中调整高度imageViews根据图像大小。
The subclass is needed to override layoutSubviews
, where you adjust the heights of the imageViews according to the image sizes.
这篇关于iOS 7.1中的UIProgressView自定义跟踪和进度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!