使用iOS7上的过渡,分隔符在左侧有15px的填充。我知道我可以在xib文件的UITableView设置上用分隔符插入功能删除这个填充,但我需要用填充保留标题文本。该怎么做呢?
默认值:

将自定义分隔符插入设置为0:

我需要保留如图2所示的分隔符,但如图1所示的带有"2013“的标题。
发布于 2014-01-09 18:43:22
对于Seperator,您可以通过Storyboard进行设置
对于header,创建一个自定义的header,如下所示
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *viewHeader = [UIView.alloc initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 28)];
UILabel *lblTitle = [UILabel.alloc initWithFrame:CGRectMake(6, 3, 136, 21)];
[lblTitle setFont:[UIFont fontWithName:@"HelveticaNeue" size:13]];
[lblTitle setTextColor:[UIColor blackColor]];
[lblTitle setTextAlignment:NSTextAlignmentLeft];
[lblTitle setBackgroundColor:[UIColor clearColor]];
[viewHeader addSubview:lblTitle];
return viewHeader;
}给它任何特定的高度。并给它提供任何文本。为区段标题创建一个数组,其中将包含您的年份。
发布于 2014-01-09 18:26:17
UITableView有一个名为viewForHeaderInSection的委托方法。如果在委托方法中删除填充,则添加填充并返回节标题视图。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.frame), 30)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 200, 25)];
// 15 pixel padding will come from CGRectMake(15, 5, 200, 25).
label.text = @"2013";
[view addSubview: label];
return view;
}你可以随心所欲地设计你的标题视图。要设置tableView标题的高度,请使用:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;希望它能帮到你。)
发布于 2016-04-13 21:31:33
您可以在表格(和页眉/页脚)和单元格本身上设置插图:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 0)];
}
if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsMake(0, 10, 0, 0)];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}https://stackoverflow.com/questions/21017019
复制相似问题