Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the tableview's visible rect

I have a tableview and I want to add as a subview a grey view with another view in order to imitate a pop-up. The problem is that the grey view doesn't cover the whole tv and the subview where I have my buttons isn't all visible if the bottom of tv is displayed.

Here is my code:

- (IBAction)orderButtonAction:(id)sender {

  _grayView = [[UIView alloc]init];
  _grayView.frame = [[UIScreen mainScreen]bounds];
  _grayView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
  _grayView.hidden = NO;
  _profileOrderView.hidden = NO;
  _tableView.scrollEnabled = NO;

  _orderButtonOutlet.hidden = YES;
   _profileOrderView.center = self.view.center;
  [_grayView addSubview:_profileOrderView];
  [_tableView addSubview:_grayView];

}

Is there a way to get the visible rect of tv and insert my grey view there?

like image 885
Stefan Olaru Avatar asked Jun 15 '26 01:06

Stefan Olaru


1 Answers

If you want the greyView to cover the entire UITableView, you should set the frame of greyView as [greyView setFrame:tableView.bounds].

If you want it to only cover the area of tableView shown, you should use the CGRectIntersection(self.frame, superview.bounds); and set it as the frame.

like image 62
Shamas S Avatar answered Jun 17 '26 23:06

Shamas S