您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

iOS UITableView 分割線與 Section 標題技巧

編輯:iOS 開發綜合

從 iOS 7 開始,UITableViewCell 使用 layoutMargins,直接改 frame 不一定能調整分割線位置。

讓分割線貼齊邊緣

可在 willDisplayCell 中將 cell 的 layoutMargins 設為 UIEdgeInsetsZero,並關閉 preservesSuperviewLayoutMargins。

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
    [cell setLayoutMargins:UIEdgeInsetsZero];
}

if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
    [cell setPreservesSuperviewLayoutMargins:NO];
}

自訂 Section 標題

可用 willDisplayHeaderView 調整 tintColor 與 textLabel 的 textColor。

隱藏空白 cell 的分割線

最簡單方式是把 tableFooterView 設為空白 UIView,讓沒有資料的儲存格不顯示線。

self.tableView.tableFooterView = [[UIView alloc] init];
  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved