Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)drawRect:(CGRect)rect
- {
- CGContextRef context = UIGraphicsGetCurrentContext();
- // let the superclass draw the label normally
- [super drawRect:rect];
- CGContextConcatCTM(context, CGAffineTransformMake(1, 0, 0, -1, 0, CGRectGetHeight(rect)));
- // create a mask from the normally rendered text
- CGImageRef image = CGBitmapContextCreateImage(context);
- CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image), CGImageGetBytesPerRow(image), CGImageGetDataProvider(image), CGImageGetDecode(image), CGImageGetShouldInterpolate(image));
- CFRelease(image); image = NULL;
- // wipe the slate clean
- CGContextClearRect(context, rect);
- CGContextSaveGState(context);
- CGContextClipToMask(context, rect, mask);
- CFRelease(mask); mask = NULL;
- maskedBackgroundColor=[UIColor colorWithRed:r green:g blue:b alpha:a];
- [maskedBackgroundColor set];
- CGContextFillRect(context, rect);
- CGContextRestoreGState(context);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement