我有一个分节的UITableView,并且想要设置一个标签(不在表格视图中)在顶部的标签文本。
我尝试使用[label setText:@"name"];
中的设置标签
(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
但这没用。其他人有如何做到这一点的想法吗?
最佳答案
试试这个
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 60)];
headerView.backgroundColor = [UIColor clearColor];
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0,0, 50, 50)];
label.backgroundColor = [UIColor yellowColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:label];
return headerView;
}