开发者

iPhone How to set a clearcolor for my custom view

开发者 https://www.devze.com 2023-01-01 12:22 出处:网络
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 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消