Ale*_*ani 24 iphone uitableview separator ios ios7
在iOS7上进行转换时,分隔符左侧有15px填充.我知道我可以在xib文件中的UITableView设置中使用分隔符插入功能删除此填充,但我需要使用填充保持标题文本.怎么做?
默认:
使用自定义分隔符插入0:

我需要像图2那样保留分隔符,但标题为"2013",如图1所示.
Nei*_*sei 44
使用SWIFT和STORYBOARD
在故事板中,您可以为TableView(标题)和单元格(分隔符)设置不同的分隔符插入.
通过在Storyboard中选择单元格并设置以下内容,将单元格的分隔符插入设置为0:
然后通过在Storyboard中选择TableView并设置以下内容,将TableView(对于标题)的分隔符插入设置为15:
可选的:
您可能还需要以编程方式将单元格上的边距设置为零,以确保分隔符从左向右一直运行.如果需要在表视图控制器的swift文件中使用此代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("YOURCELL", forIndexPath: indexPath) as! UITableViewCell
// THIS IS THE IMPORTANT PART...
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
return cell
}
Run Code Online (Sandbox Code Playgroud)
Xei*_*han 15
对于Seperator,您可以通过Storyboard进行设置
并为标题创建这样的自定义标题
- (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;
}
Run Code Online (Sandbox Code Playgroud)
给它任何特定的高度.并给它任何文字.为包含年份的部分标题创建一个数组.