views:

161

answers:

1

I am new to iphone development.I have displayed the text in the header label.Now i want to align the text to center. I using the following code

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0,300.0,44.0)];

UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor brownColor];

headerLabel.textColor = [UIColor whiteColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:15];
headerLabel.frame = CGRectMake(0.0, 0.0, 500.0, 22.0);  
headerLabel.text = @"Hello"; // 
[customView addSubview:headerLabel];
return customView;
}

"hello" should be displayed at the center of the header label.Please help me out.Thanks.

+2  A: 

Try this:

headerLabel.textAlignment = UITextAlignmentCenter;
Alex
Thanks for your valuable answer....
Warrior