我用下面的代码在group tableview title header上设置标题,但是默认文本是AlignmentLeft,如何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);
}
}
最佳答案
这样试试,
- (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;
}
为页眉设置一些默认高度,
- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section {
switch(section) {
case 0:
case 1:
default:return 20;
}
}
关于iphone - 如何将 titleForHeaderInSection 的文本设置为 AlignmentCenter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15740704/