使用图像创建自定义进度条
我想做的几乎就是创建以下图像:
这是一个进度条,它将显示客户端在该选项中获得了多少票。我怎样才能做到这一点?我想知道是否可以使用遮罩(就像在 Flex 中一样),但是我在网上找到的所有遮罩实现都是为 UIImage
做遮罩,而不是为 UIImageView< /代码>。我无法在
UIImage
中进行遮罩,因为两个图像具有相同的尺寸。我必须使用图像的 X 和 Y 来裁剪它们?!那么,有什么建议吗?
以下是我必须创建进度条的两个图像:
干杯。
Pretty much what I am trying to do, is create the following image:
So this is a progress bar, which will show how many votes the client get in that option. How can I do that? I was wondering if I can use a mask (as I would in flex), but all the masking implementations that I found on the web are doing masks for UIImage
s, and not for UIImageView
. I cannot do the mask in the UIImage
, because the two images have the same dimensions. I have to use the X and Y of the images to crop them?! So, any suggestions?
Here are the two images that I have to create that progress bar:
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想去掉每张图像中间所有相同的部分。
然后执行以下操作:
you want to get rid of all of the same bit in the middle of each image.
then do something like:
Grady Player 的回答很棒。对于任何使用此功能的人来说,只是一个小注释。我尝试更新两个 UIImageView 的框架来更新“进度”。我尝试使用“setNeedsDisplay”强制更新,但无济于事。 (sizeToFit 也引起了问题)。
不管怎样,我想出如何更新现有进度条的进度的唯一方法是使用我的新尺寸调用“setFrame:CGRectMake”。
Grady Player's answer is great. Just a small note, for anyone that uses this. I tried to update the frames of the two UIImageView's to update the "progress". I tried to force an update with "setNeedsDisplay", but to no avail. (sizeToFit caused problems too).
Anyway, the only way I figured out how to update the progress of an existing progress bar was to call "setFrame:CGRectMake" with my new dimensions.