如何为UITableview单元格设置Header For Header?

时间:2017-01-09 06:38:52

标签: ios objective-c uitableview

我做了一个工作正常的演示。 我一度陷入困境。

图像

enter image description here

问题

1)如何使这种类型的功能Header和bellow标题状态,日期和注释?

2)如何在单元格和标题之间设置下划线“看到它是浅灰色”?

4 个答案:

答案 0 :(得分:0)

1.您可以在此UITableViewDelegate的函数中返回标题视图。

optional public func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 
// custom view for header. will be adjusted to default or specified header height

2.您可以以编程方式添加该行,或尝试将表格视图的样式设置为Plain

答案 1 :(得分:0)

在viewForHeaderInSection中播放自定义视图

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
/// create your custom view//
return customView;
}

答案 2 :(得分:0)

1.创建您想要的自定义视图(如您发布的图像)

2.将该视图作为此方法中节的标题返回

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

答案 3 :(得分:0)

使用此委托方法。

   -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, HEADER_H)];
         UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0, HEADER_H-2, tableView.frame.size.width, 1)];
        lineView.backgroundColor=[UIColor darkGrayColor];

        [headerView addSubview:lineView];

        return headerView;
 }