【发布时间】:2018-04-04 15:31:15
【问题描述】:
在 iOS 11 中,我注意到在控制中心他们有一个标题视图,它的底部和表格视图单元格之间有空间。您将如何实现这一目标? heightForHeaderInSection 仅更改标题顶部与其上方任何内容之间的高度,但不更改底部和 tableview 之间的空间。
更新: 这是对我有用的代码,其他任何人都想知道。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, tableView.frame.size.width - 30, 50)];
headerLabel.text = @"Text goes here";
headerLabel.numberOfLines = 0;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.textAlignment = NSTextAlignmentLeft;
[headerLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:12.0]];
// I could not figure out the exact text color :(
[headerLabel setTextColor:[UIColor headingTextColor]];
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, headerLabel.frame.size.width, 200)];
[headerView addSubview:headerLabel];
return headerView;
}
【问题讨论】:
标签: ios objective-c xcode ios11