iOS必威: 动态变色的Label

必威 1BlendColor.gif

@interface WYColorLabel : UILabel/// 变色比例 0~1@property (nonatomic, assign) CGFloat colorRatio;/// 混合颜色@property (nonatomic, strong) UIColor *blendColor;@end#import "WYColorLabel.h"@implementation WYColorLabel- drawRect:rect { // 1.绘制文字 [super drawRect:rect]; rect.size.width *= self.colorRatio; // 2.设置颜色 [self.blendColor set]; UIRectFillUsingBlendMode(rect, kCGBlendModeSourceIn);}- setColorRatio:colorRatio { _colorRatio = colorRatio; [self setNeedsDisplay];}@end

github Demo:

本文由必威发布于必威-编程,转载请注明出处:iOS必威: 动态变色的Label

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。