自定义形状进度视图

自定义形状进度视图

问题描述:

我正在寻找有关自定义进度视图的解决方案。

I'm looking out for some solution regarding the custom progress view.

基本上,我想填充下面的图像来表示加载进度,就像

Basically, i would like to fill the image below to represent the loading progress,just like the one's we have in games.

任何想法如何实现?

使用CoreGraphics进行屏蔽:

Masking using CoreGraphics:

UIImage *img = [UIImage imageNamed:@"imagetomask.png"];
CGImageRef maskRef = [UIImage imageNamed:@"mask.png"].CGImage;
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                                CGImageGetHeight(maskRef),
                                                CGImageGetBitsPerComponent(maskRef),
                                                CGImageGetBitsPerPixel(maskRef),
                                                CGImageGetBytesPerRow(maskRef),
                                                CGImageGetDataProvider(maskRef), NULL, false);

CGImageRef maskedImage = CGImageCreateWithMask([img CGImage], mask);
[imageView setImage:maskedImage];

您的 mask.png 应该不是透明的图像像倒置的alpha一样填充-黑色代表可见部分,白色代表透明。

Your mask.png should be non-transparent image filled like inverted alpha - black for visible parts, white for transparent.