Ios 如何设置UITableview单元格标题下的行?
我做了一个演示,效果很好。 我一度陷入困境Ios 如何设置UITableview单元格标题下的行?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我做了一个演示,效果很好。 我一度陷入困境 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, HEADER_H)]; UIView *lineView
-(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;
}
形象
-(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;
}
问题:
1) 如何使这种类型的功能标题和下面的标题状态、日期和注释
-(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;
}
2) 如何在单元格和标题之间设置下划线“查看为浅灰色?”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
-(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;
}
2.您可以通过编程方式添加该行,或者尝试将表格视图的样式设置为
普通
在viewForHeaderInSection中创建自定义视图
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
/// create your custom view//
return customView;
}
-(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;
}
1.根据需要创建自定义视图(如您发布的图像)
-(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;
}
2.在此方法中将该视图作为节的标题返回
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
-(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;
}
使用此委托方法
-(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;
}
创建自定义视图,并在
UITableViewDelegate
@NiravD的viewForHeaderInSection
方法中返回该视图,但他希望每个单元格都使用该视图我只希望从标题和单元格中使用,而不是每个单元格我都使用self.tableview.separatorStyle=uitableviewCellseparatorstyle;对于隐藏线cell@NiravDLol:)是的,我必须读。请给我目标c