Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set UILabel text from UITableView header section

I've got an sectioned UITableView and want to set a label (not in the tableview) the text of the label that's on top.

I tried settings label with [label setText:@"name"]; in

 (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 

but that didn't work. Anyone else have ideas how to do this?

like image 623
sjors Avatar asked Apr 07 '26 18:04

sjors


1 Answers

Try this

-(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;
}
like image 104
Radu Avatar answered Apr 09 '26 20:04

Radu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!