how to set text of titleForHeaderInSection to AlignmentCenter
ios, iphone
Solution
Try like this,
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel * sectionHeader = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
sectionHeader.backgroundColor = [UIColor clearColor];
sectionHeader.textAlignment = UITextAlignmentCenter;
sectionHeader.font = [UIFont boldSystemFontOfSize:10];
sectionHeader.textColor = [UIColor whiteColor];
switch(section) {
case 0:sectionHeader.text = @"TITLE ONE"; break;
case 1:sectionHeader.text = @"TITLE TWO"; break;
default:sectionHeader.text = @"TITLE OTHER"; break;
}
return sectionHeader;
}
set some default height for Header,
- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section {
switch(section) {
case 0:
case 1:
default:return 20;
}
}
Problem
i used the follow code to set the title at the group tableview title header,but default the text is AlignmentLeft,how to AlignmentCenter? ``` - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if(section==0){ return NSLocalizedString(@"more_titlehead_one", nil); }else if (section==1){ return NSLocalizedString(@"more_titlehead_two", nil); }else{ return NSLocalizedString(@"more_titlehead_three", nil); } } ```