Custom drawing on top of UITableView

I have some problems composing custom content on a UITableView. What I did is subclass UITableView and overwrite the drawRect (void) method something like this:

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    [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 is under the cells of the table. Even if I comment on the call [super drawRect: rect] in the method above, the cells will be displayed.

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

+3
source share
1 answer

, . UIImageView .

UIImageView x/y.

[self.view addSubView:myView];
+1

Source: https://habr.com/ru/post/1750257/


All Articles