将 UIImageView 切片为自定义形状
我有一个包含圆形图像的 UIImageView。我希望能够删除图像的一部分(同时保持透明度)以创建切片缺失的效果,如下所示。我的最终目标是创建类似 iTunes 应用程序的东西,当您播放歌曲预览时,圆圈会按顺时针方向慢慢填充。
I have a UIImageView that contains an image of a circle. I would like to be able to remove a portion of the image (while maintaining the transparency) to create the effect of a slice missing as shown below. My ultimate goal is to create something like the ITunes app, where as you play a song preview, the circle slowly fills in, in a clockwise direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您除了进度显示之外不需要圆圈图像,您可以跳过
UIImageView
并仅使用 CoreGraphics 绘制进度指示器。基本步骤是:CGContextBeginPath
CGContextAddArc
添加弧线 使用CGContextFillPath
填充路径CGContextClosePath
对每个进度步骤重复此操作,每次更改弧的端点。
If you don't need the image of the circle for anything other than the progress display, you could skip the
UIImageView
and just use CoreGraphics to draw the progress indicator. The basic steps would be:CGContextBeginPath
CGContextAddArc
CGContextFillPath
CGContextClosePath
Repeat this for each progress step, changing the endpoint of your arc each time.
我使用以下代码实现了类似的填充圆:
(委托提供了一个介于 0 和 1 之间的值)
我还没有弄清楚如何动态地填充它,尽管我猜这在很大程度上取决于它所使用的特定上下文。希望它有任何帮助!干杯。
I've implemented a similar filling-up circle with the following code:
(the delegate provides a value between 0 and 1)
I haven't figured out how to dynamically make it fill up yet, though I guess that this would depend heavily on the specific context where it is being used. Hope it is of any help! Cheers.