开发者

Custom drawing on top of a UITableView

I have some problems drawing some custom content over a UITableView. What I did was subclass UITableView and overwrite the -(void)drawRect method something like this:

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContex开发者_开发知识库t();

    [super drawRect:rect];

    CGContextSetRGBFillColor(ctx, 255, 0, 0, 1.0f); 
    CGContextFillRect(ctx, CGRectMake(10, 10, 10, 10));
}

The problem is that i see my red rectangle but it's underneath the table view cells. Even if I comment the [super drawRect:rect] call in the method above, the cells will still display.

My guess is that internally whoever calls the drawRect method for the tableview, draws the cells afterwards, meaning the overwriting drawRect is not enough because the cells will always be drawn afterwards.


If you need the image to cover the tableview. Add an UIImageView as a subview to the view instead.

One can create a frame for your new UIImageView and specify the x/y coordinates as well.

[self.view addSubView:myView];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜