iOS 7.1 中的 UIProgressView 自定义轨道和进度图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22311516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIProgressView custom track and progress images in iOS 7.1
提问by Tom Hamming
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.
iOS 7.1 似乎破坏了UIProgressView
. 用于成功自定义进度视图的代码现在生成默认外观。
I set up a sample project that does this in viewDidLoad
:
我设置了一个示例项目,它在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?
我仍然得到默认外观。我已经通过并验证了img
它不是预期的那样。这是怎么回事?
UPDATE:There is an OpenRadarfor this, and I've also filed a radar of my own complete with a sample project.
更新:有一个OpenRadar为此,我还提交了一个我自己的完整雷达和一个示例项目。
UPDATE 2:As noted by Axy below, you have to add this to get the JEProgressView to work correctly:
更新 2:正如下面 Axy 所指出的,您必须添加它才能使 JEProgressView 正常工作:
_progressBar.tintColor = [UIColor clearColor];
采纳答案by John Estropia
This is very annoying. I didn't find a way to fix this without subclassing UIProgressView
.
这很烦人。我没有找到没有子类化的方法来解决这个问题UIProgressView
。
Anyway here's how I fixed this: https://gist.github.com/JohnEstropia/9482567
无论如何,这就是我解决这个问题的方法:https: //gist.github.com/JohnEstropia/9482567
You will have to change occurrences of UIProgressView
to JEProgressView
, including those in NIBs and storyboards.
您必须将 的出现更改UIProgressView
为JEProgressView
,包括在 NIB 和故事板中的出现。
Basically, you'd need to force assigning the images directly to the UIProgressView
's children UIImageView
s.
基本上,您需要强制将图像直接分配给UIProgressView
的 children UIImageView
。
The subclass is needed to override layoutSubviews
, where you adjust the heights of the imageViews according to the image sizes.
子类需要覆盖layoutSubviews
,您可以根据图像大小调整 imageViews 的高度。
回答by matt
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.
你是对的。自 7.1 首次在 Xcode 5.1 种子 1 中出现以来,此错误一直存在。我为 Xcode 5.1 的所有 5 个种子提交(并重新提交)相同的错误,现在在 Xcode 5.1 上。但苹果并没有修复它。
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
).
请也提交此错误!喜欢的可以参考我的bug:15547259,越多越好!我认为这是严重损坏,因为这意味着运行良好的应用程序现在损坏了(如果它使用带有 的进度视图progressImage
)。
回答by Axy
I used John Estropia solution, but it was showing the blu tint bar in overlay to mine, with quite a strange graphical effect.
我使用了 John Estropia 解决方案,但它在我的叠加层中显示了蓝色色调条,具有相当奇怪的图形效果。
I added
我加了
_progressBar.tintColor = [UIColor clearColor];
_progressBar.tintColor = [UIColor clearColor];
and It went just fine. Thanks for the solution man.
一切顺利。感谢解决问题的人。
回答by improgrammer
Hello friends I have used the following code to add UIProgressView in my app:
你好朋友我已经使用以下代码在我的应用程序中添加 UIProgressView:
UIProgressView *progressView;
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.progressTintColor[UIColor colorWithRed:187.0/255 green:160.0/255 blue:209.0/255 alpha:1.0];
[[progressView layer]setCornerRadius:10.0f];
[[progressView layer]setBorderWidth:2.0f];
[[progressView layer]setMasksToBounds:TRUE];
progressView.clipsToBounds = YES;
[[progressView layer]setFrame:CGRectMake(30, 295, 260, 25)];[[progressView layer]setBorderColor[UIColor whiteColor].CGColor];
progressView.trackTintColor = [UIColor clearColor];
[progressView setProgress: (float)count/15 animated:YES];
Hope the code will be helpful to you, I found it here : Source of Code
希望代码对您有所帮助,我在这里找到了:代码源
回答by Glenn S?nderskov
I have tried to implement the JEProgressView files from John Estropia - but it doesn't work. I must have done something wrong - but I'm a little new to this. Can someone explain how exactly to do this? I know it might be a stupid question - but after a lot of googling I thought asking was the only way.
我试图从 John Estropia 实现 JEProgressView 文件 - 但它不起作用。我一定做错了什么 - 但我对此有点陌生。有人可以解释一下如何做到这一点吗?我知道这可能是一个愚蠢的问题 - 但经过大量谷歌搜索后,我认为询问是唯一的方法。
回答by Aanabidden
For me this worked for iOS version 7.1 and above for progress image:
对我来说,这适用于 iOS 7.1 及更高版本的进度图像:
if ([[UIDevice currentDevice] systemVersion] >= 7)
self.progressView.tintColor = [UIColor colorWithPatternImage:img];
回答by ???
With Xcode5 it is now possible to make resizable images with Interface Builder
too. We can specify the resizing direction and content inset and select the area of to be strecthed right within the interface builder.
使用 Xcode5 现在也可以制作可调整大小的图像Interface Builder
。我们可以指定调整大小的方向和内容插入,并在界面构建器中选择要拉伸的区域。
To avail this feature you have use Asset Catalog
for the image you want to resize.
回答by ninjaproger
I'm also catched this bug. I tried to fix it playing with UIProgressView properties but without result. John's Estropia solution posted above, also don't work for me, maybe it's not support auto layout, so I made my own temporary solution for bypassing this bug. https://github.com/ninjaproger/AKProgressView
我也遇到了这个bug。我尝试使用 UIProgressView 属性修复它,但没有结果。上面张贴的 John 的 Estropia 解决方案也对我不起作用,也许它不支持自动布局,所以我制作了自己的临时解决方案来绕过这个错误。https://github.com/ninjaproger/AKProgressView