iOS 给TableView添加Footer或Header
程序员文章站
2024-03-24 09:58:52
...
给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;
}
#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
#define kMulriple 2
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (section == 0) {
UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH , 60.0)];
UILabel *la = [[UILabel alloc ]init ];
la.frame = CGRectMake(20, 20*kMulriple, SCREEN_WIDTH- 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;
}
效果如下: