缩进UITableView标题标签不工作
问题描述:
我正在尝试创建标题标签并缩进它,以便它出现在表视图上方而不是刷新到屏幕左侧。我已经实现了下面的代码,它改变了标题标签的外观,但没有改变位置。缩进UITableView标题标签不工作
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.frame.size.width,30)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,0, headerView.frame.size.width, 30)];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.textColor = [UIColor whiteColor];
headerLabel.shadowColor = [UIColor grayColor];
headerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.text = @"Header Label";
[headerView addSubview:headerLabel];
return headerLabel;
}
任何人都可以看到我做错了什么?
感谢
答
我建议你修改这个代码行:
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.frame.size.width,30)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,0, headerView.frame.size.width, 30)];
有:
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,30)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,0, 100, 30)];
然后递增或递减的价值10填充左,0填充顶部...
希望帮助
返回headerView而不是headerLabel,还有一件事,给头部分的高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 35; }。你可以看到你的标题视图。 – Nirmalsinh 2013-07-30 10:36:12