Heim > Fragen und Antworten > Hauptteil
试了用-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section方法,但是不知为什么并没有什么改变。。还有什么办法吗?或者我上面的方法可能问题出在哪些地方
PHP中文网2017-04-17 17:58:16
如果我没理解错的话你是想改变第一个 Cell 到顶部的距离,可以通过填充一个空 UIView
到 tableHeaderView
,然后通过这个 View 的 Frame Height 来控制。
UIView *tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 10)]; // 这里 10 就是你想要的高度
tableView.tableHeaderView = tableHeaderView;
伊谢尔伦2017-04-17 17:58:16
如果只是改变第一个cell到顶部的距离,最简单直接粗暴的方法就是给你的tableView的顶部与父view的顶部之间预留你想要的空间(也就是所谓的第一个cell上面的距离),这样既可
PHP中文网2017-04-17 17:58:16
不知道你视图的目录层级是什么,要设置header的高度,首先你要有一个header。
//swift
// 返回header的高度
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 5
}
// 在header中添加一个视图
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView()
view.backgroundColor = UIColor.redColor()
return view
}