UITableView のセルの区切り線(Separator)をテーブルの端まで伸ばすTIPS
いつもどおりStoryboard から separetorinsetいじって終わるかとおもいきや終わらず
少しハマったのでメモ
どうやらiOS8で追加されたマージンも合わせて調節しないといけないようだ。
willDisplayCell
// セパレータの設定
-(void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath{
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
上記処理を追加したらできた。
下記2つのプロパティを調整している
layoutMargins は自分自身のサブビューとのマージンを
preservesSuperviewLayoutMargins はlayoutMargins の値をスーパービューから引き継ぐかどうかの真偽値を表している。
どちらもiOS8から追加されたUIView のプロパティのようだ。
セルのスーパービューからサブビューとの間のマージンを引き継いでしまっているため、
それを無効化しないとセパレータがマージンに影響されてしまうようだ。