Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. - (void)drawRect:(CGRect)rect
  2. {
  3. CGContextRef context = UIGraphicsGetCurrentContext();
  4.  
  5. // let the superclass draw the label normally
  6. [super drawRect:rect];
  7.  
  8. CGContextConcatCTM(context, CGAffineTransformMake(1, 0, 0, -1, 0, CGRectGetHeight(rect)));
  9.  
  10. // create a mask from the normally rendered text
  11. CGImageRef image = CGBitmapContextCreateImage(context);
  12. CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image), CGImageGetBytesPerRow(image), CGImageGetDataProvider(image), CGImageGetDecode(image), CGImageGetShouldInterpolate(image));
  13.  
  14. CFRelease(image); image = NULL;
  15.  
  16. // wipe the slate clean
  17. CGContextClearRect(context, rect);
  18.  
  19. CGContextSaveGState(context);
  20. CGContextClipToMask(context, rect, mask);
  21.  
  22. CFRelease(mask); mask = NULL;
  23. maskedBackgroundColor=[UIColor colorWithRed:r green:g blue:b alpha:a];
  24. [maskedBackgroundColor set];
  25. CGContextFillRect(context, rect);
  26.  
  27.  
  28. CGContextRestoreGState(context);
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement