iOS 7.1 中的 UIProgressView 自定义轨道和进度图像 [英] UIProgressView custom track and progress images in iOS 7.1

查看:7
本文介绍了iOS 7.1 中的 UIProgressView 自定义轨道和进度图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 中设置了一个示例项目:

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.

无论如何,我是这样解决这个问题的: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 的子UIImageViews.

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

需要子类来覆盖 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆