UITableView expands the background color below the cells

I have UITableViewwhich I gave headerViewwith a green background. I also gave UITableViewthe same green background color so that when dropped tableViewit looked like a colorless color above tableView. It works great.

The problem is that mine tableViewonly has 4 lines, and below is green.

enter image description here

How can I show white below the lines instead, so that I only see the green background color when changing tableView?

+4
source share
3 answers

, , UIRefreshControl:

CGRect frame = self.tableView.bounds;
frame.origin.y = -frame.size.height;

UIView *bgView = [[UIView alloc] initWithFrame:frame];
bgView.backgroundColor = [UIColor greenColor];

[self.tableView insertSubview:bgView atIndex:0]; 
+7

, , 400 View, .

-(void)viewWillLayoutSubviews {
    self.tableView.contentSize = CGSizeMake(self.tableView.frame.size.width, 500);
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat h = (indexPath.row == 4)? 400:44;
    return h;
}

contentSize viewWillLayoutSubviews , reset , .

+2

, , , . , tableView: ( )

-(void) viewDidLoad {

    self.tableView.backgroundColor = [UIColor whiteColor];

    headerView = [[UIView alloc] init];
    headerView.backgroundColor = [UIColor greenColor];

    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, -50, 320, 120)];
    lab.backgroundColor = [UIColor greenColor];
    [headerView addSubview:lab];

    self.tableView.tableHeaderView = headerView;

} 


#pragma mark - Table view data source
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

  return 80;

}


-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

  return headerView;

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  // Return the number of sections.
  return 1;
}
0

All Articles