实现效果 类似朋友圈头部图片
1、设置样式
//这里需要设置UITableViewStyleGrouped 这个是一起滚动 如果是 UITableViewStylePlain 是不滚动的
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(x, y, width, height) style:UITableViewStyleGrouped];
2、设置高度 (这一点很多文章都没提到过,我找了半天才找到)
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 200;
}
3、设置UIView
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView * view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 200)];
view.backgroundColor=[UIColor redColor];
return view;
}
如此这就可以了
参考资料:
http://blog.youkuaiyun.com/xiaobo16/article/details/7801745