LoginSignup
75
76

More than 5 years have passed since last update.

iOS8でUITableViewのseparatorInsetに値をセットしても上手く行かない場合の対処法

Last updated at Posted at 2014-09-09

iOS8 beta5で検証。

UITableViewでiOS7から、デフォルトでテーブルの境界線(separator)が左から15pxマージンを取るようになってますが、それを左いっぱいから境界線を引きたい場合は、

self.tableview.separatorInset = UIEdgeInsetsZero;

のように設定したり、StoryboardのSeparatorのleftを0に設定しているとします。

iOS8(beta5)はなぜか上記の設定が反映されずに、デフォルトの15pxマージンが取られるようになってしまっていました。

その時の対処法。

- (void) viewDidLoad {
    [...]

    self.tableView.separatorInset = UIEdgeInsetsZero;
    if ([self.tableView respondsToSelector:@selector(layoutMargins)]) {
        self.tableView.layoutMargins = UIEdgeInsetsZero;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    [...]

    cell.separatorInset = UIEdgeInsetsZero;
    if ([cell respondsToSelector:@selector(layoutMargins)]) {
        cell.layoutMargins = UIEdgeInsetsZero;
    }
}

こんな感じで、iOS8から追加されたlayoutMaginsというプロパティに設定してあげると、左端から境界線が引かれるようになりました!


iOS8の対応、それなりに大変ですね〜。

今日の未明(2014/09/09)にiPhone6発表ありそうですが、特に横幅の変更を考慮した修正を入れていくのが結構大変です。Portrait限定で、横幅320px前提で作っちゃってたりしてると特にしんどいですね。対応しないアプリの場合、iPhone4s→iPhone5のときのように端を黒くしたような対応がされるのかな・・・

75
76
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
75
76