2014-02-17 25 views
0

嘿,我嘗試改變我的頁腳的寬度部分:改變頁腳部分的寬度不行

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

UIView *viewFooter = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 300, 44)]; 

[viewFooter setBackgroundColor:[UIColor blueColor]]; 

return viewFooter; 
} 

但頁腳是永遠的寬度爲實現代碼如下(320.0f)....

回答

3

是的,表視圖將始終使節頭成爲表的整個寬度。

最簡單的解決方案是讓您的「真實」頁腳成爲實際頁腳視圖的子視圖。

事情是這樣的:

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ 
    UIView *mainFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 

    UIView *viewFooter = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 300, 44)]; 
    [viewFooter setBackgroundColor:[UIColor blueColor]]; 
    viewFooter.autoresizingMask = UIViewAutoresizingMaskFlexibleWidth; 
    [mainFooter addSubview:viewFooter]; 

    return mainFooter; 
} 

// You must implement this when you implement viewForFooterInSection 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 
    return 44; 
} 
1

如果需要在所需的頁腳自定義視圖中添加一個容器,並且它的大小與實際的tableview不一樣,則需要添加一個容器。這應該工作:

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

    UIView *viewFooter = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 300, 44)]; 
    [viewFooter setBackgroundColor:[UIColor blueColor]]; 


    // Create a footer container that has a fixed width 
    // but in which you can adjust subviews frame as you want. 
    // 
    UIView *footerContainer = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 320, 44)]; 
    [footerContainer addSubview:viewFooter]; 

    return footerContainer; 
}