2011-12-28 36 views
1

我是个在我的代码使用CGRectMake相同的X位置,但它不影响下面的代码节头始终神韵:到

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

    UILabel *v=[[UILabel alloc]initWithFrame:CGRectMake(100, 0, 150, 10)]; 
    [v setBackgroundColor:[UIColor clearColor]]; 
    [v setText:@"Apartments that matches your search ..."]; 
    [v setTextColor:[UIColor whiteColor]]; 
    [v setFont:[UIFont systemFontOfSize:13.0f]]; 

    return v; 

} 
return NULL; 
} 

我想要的UILabel在TableView中的中心,请大家帮忙

回答

3
UILabel *v=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 10)]; 
[v setTextAlignment:UITextAlignmentCenter]; 
1

任何您从这个方法返回的视图会自动缩放并定位以填充屏幕的宽度。将标签的textAlignment设置为居中以获得所需的效果。