@synthesize redValue; @synthesize greenValue; @synthesize blueValue; -(id) initWithFrame: (CGRect)frame { if ((self = [super initWithFrame:frame])) { redValue = 0; // Default red value greenValue = .50; // Default green value blueValue = 1.0; // Default blue value } return self; } -(void) drawTextInRect: (CGRect)rect { CGSize textShadowOffest = CGSizeMake(0, 0); float textColorValues[] = {redValue, greenValue, blueValue, 1.0}; CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSaveGState(ctx); CGContextSetShadow(ctx, textShadowOffest, 4); CGColorSpaceRef textColorSpace = CGColorSpaceCreateDeviceRGB(); CGColorRef textColor = CGColorCreate(textColorSpace, textColorValues); CGContextSetShadowWithColor(ctx, textShadowOffest, 4, textColor); [super drawTextInRect:rect]; CGColorRelease(textColor); CGColorSpaceRelease(textColorSpace); CGContextRestoreGState(ctx); }
转载于:https://www.cnblogs.com/liuxingzi/archive/2012/11/19/3404263.html