如何在视图的图层颜色发生变化时使不同的颜色外观 [英] How to make the different colour appearance while layer color of the view is changing
问题描述
我正在做一些自定义下载进度栏(子类) UIButton
(或)我也可以在 UIView $中执行此操作c $ c>,一切都很好,现在我想改变标题的颜色作为收益的进度,例如你可以在下面的图片中看到显示我现在得到的,
I am doing some custom download progresses bar in side the (subclassed) UIButton
(or) i can also do that in UIView
, every thing is fine, now i want change the colour of the title as the progress the proceeds, for example as u can see in the below image shows what is now i am getting,
我想要的是如下图像
我希望在下载过程中将标题的颜色更改为白色或其他颜色,有什么方法我可以做,任何示例代码这个。
i want change the color of the title to white or some other color as download proceeds, is there any way i can do, any sample code for this.
我通过使用以下代码实现这一目标
i am achieving this by using below code
- (void)drawInContext:(CGContextRef)progressContext
{
CGContextSetFillColorWithColor(progressContext, self.progressLayerColor.CGColor);
CGMutablePathRef Path = CGPathCreateMutable();
CGRect boundsRect = self.bounds;
CGPathMoveToPoint(Path, NULL, boundsRect.origin.x, boundsRect.origin.y);
CGPathAddRect(Path, NULL, CGRectMake(0, 0, self.progress, 35));
CGPathCloseSubpath(Path);
CGContextAddPath(progressContext, Path);
CGContextFillPath(progressContext);
CGContextSetBlendMode(progressContext, kCGBlendModeClear);
CGContextFillPath(progressContext);
CGPathRelease(Path);
}
推荐答案
随着帮助@jrturton建议我能够制作这种进度条吧,
With the help of what @jrturton suggested i am able to make this kind of progress bar,
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = _labelGreen.bounds;//it the label on top with green background and white text color
CGMutablePathRef mutPath = CGPathCreateMutable();
CGPathMoveToPoint(mutPath, NULL, 0, 0);
CGPathAddRect(mutPath, NULL, CGRectMake( 0, 0, progress, _labelGreen.frame.size.height)); //as the progress cganges the width of mask layer also changes
maskLayer.path = mutPath;//set the path
_labelGreen.layer.mask = maskLayer;
结果输出将如下图所示
the resulted output will be like below image
这篇关于如何在视图的图层颜色发生变化时使不同的颜色外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!