iOS 給TableView新增Footer或Header
給TableView新增Footer或Header 下面僅以footer示例
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == 0) {
return 0.1;
}else if (section == 1){
return 4;
}else{
return 0.000001f; // 設定為0.0001 是為了不懸浮
}
return 0.1;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (section == 2) {
UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth , 60.0)];
UILabel *la = [[UILabel alloc ]init ];
la.frame = CGRectMake(20, 20*kMulriple, kScreenWidth- 40 , 20);
la.text = @"----沒有更多記錄了----";
la.textColor = [UIColor lightGrayColor];
la.font = [UIFont systemFontOfSize:15.f*kMulriple];
la.textAlignment = NSTextAlignmentCenter;
[footerView addSubview:la];
return footerView;
}
return nil;
}
效果如下: