带光晕的UILabel源代码

   
@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);
}
     

posted on 2012-11-19 12:02  流れ星ーー  阅读(150)  评论(0编辑  收藏  举报

导航