tableView 分組間距

在使用IOS的UITableView時,時常會用到它的UITableViewStyleGrouped分組多section屬性。而默認的情況下使用該屬性後section之間的間距會比較大,看着很不舒服。那麼可以通過以下的代理方法配置UITableView各個section的間距。
原理其實很簡單,顯示效果的各個section間距其實是section頭部和底部的組合。配置他們的間距就是配置各個section的頭部和底部。具體如下示例:
摺疊展開C/C++ Code複製內容到剪貼板
//section頭部間距   
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section   
{   
    return 1;//section頭部高度   
}   
//section頭部視圖   
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section   
{   
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];   
    view.backgroundColor = [UIColor clearColor];   
    return [view autorelease];   
}   
//section底部間距   
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section   
{   
    return 1;   
}   
//section底部視圖   
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section   
{   
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];   
    view.backgroundColor = [UIColor clearColor];   
    return [view autorelease];   
}  
發佈了19 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章