【发布时间】:2025-12-28 01:25:15
【问题描述】:
初始化 UIViewController 代码:
self.view.backgroundColor= [UIColor whiteColor];
CGSize boundsSize = self.view.bounds.size;
CGRect rectTableViewFrame = CGRectMake(0, 0, boundsSize.width, boundsSize.height - 64);
UITableView* contentTableView = [[UITableView alloc] initWithFrame:rectTableViewFrame];
contentTableView.backgroundColor = [UIColor clearColor];
contentTableView.separatorColor = [UIColor clearColor];
contentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
接下来添加UITableView自定义视图(header):
CustomView* customView = [[CustomView alloc] init];
CGRect customViewFrame = customView.frame;
customViewFrame.origin.y = - customView.size.height;
customView.frame = customViewFrame;
contentTableView.contentOffset = CGPointMake(0, customViewFrame.origin.y);
contentTableView.contentInset = UIEdgeInsetsMake(customViewFrame.frame.size.height, 0, 0, 0);
[contentTableView addSubview: customView];
问题:当滚动contentTableView顶部customView有一条灰线...如何删除这个? 我不使用方法:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
但如果使用白色背景颜色的简单视图,则没有线条。
【问题讨论】:
-
尝试评论 contentInset 行并检查一次。
标签: ios uitableview