I am creating a custom StyleLabel by extending the UIView, which provides a link for particular type of strings. I have successfully implemented this functionality.
I am using this label in TableViewCell along with开发者_如何学Python UILabel.i set UILabel & StyleLabel background color is set to clearColor. UILabel works fine, but StyleLabel shows background in blackColor.
I am not sure what is the problem with the following code.
Here is the drawRect method of CustomLabel class
-(void) drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
[[UIColor clearColor] setFill];
CGContextAddRect(ctx, rect);
CGContextDrawPath(ctx, kCGPathFill);
[_text drawText:ctx];
}
Thanks Sasikumar
If a view is opaque, then clearColor will draw as black. Be sure to set theView.opaque = NO
for any view that should be clear or transparent.
This code is not needed after CGContextClearRect:
[[UIColor clearColor] setFill];
CGContextAddRect(ctx, rect);
CGContextDrawPath(ctx, kCGPathFill);
精彩评论