![](/img/trans.png)
[英]How to get the last cell separator of a UITableView take the full length?
[英]iOS7 last cell in UITableView section forces full width separator
下面的UITableView
有自定義UITableViewCells
,我可以使用自定義UITableViewCell
中的這一行調整分隔符:
self.separatorInset = UIEdgeInsetsMake(0, kDefaultSeparatorLeftInset, 0, 0);
但是,該部分底部的單元格有一個默認分隔符,它會覆蓋我設置的自定義UIEdgeInsets
。
我希望所有分隔符的寬度相同,有沒有辦法在不重新繪制分隔符的情況下執行此操作?
一些實驗后,我發現的唯一真正的解決辦法是設定UITableViewStyle
到UITableViewStylePlain
和設置使用空頁腳:
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;
}
這會不會是一些令人滿意的解決方案,因為UITableViewStylePlain
不提供所有的功能UITableViewStyleGrouped
,但它給了我沒有全寬分離的部分。
經過一些實驗,我找到了解決方案! tableFooterView可以像這樣覆蓋分隔符:
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
UIView *v2 = [[UIView alloc] initWithFrame:CGRectMake(0, -1, 320, 2)];
v2.backgroundColor = [UIColor whiteColor];
v.backgroundColor = [UIColor whiteColor];
[v addSubview:v2];
self.tableView.tableFooterView = v;
在tableView本身上使用separatorInset
屬性,而不是在單個單元格上。 tableView的separatorInset設置默認插入,可以由單元格覆蓋,以及底部“額外”單元格的插入。
給桌子一個空頁腳:
self.tableFooterView = [[UIView alloc] init]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.