我有一个分段的 UITableView 并想设置一个标签(不在 tableview 中)顶部标签的文本。
我尝试在
中使用[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;
}
关于objective-c - 从 UITableView 标题部分设置 UILabel 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14482732/