Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid extra leading margin for UITableViewCell under iOS 11

All custom UITableViewCells which are compiled under iOS11 (Xcode 9) are getting an extra leading margin but not with iOS10 (Xcode 8). Please see the images.

iOS 10, compiled with Xcode 8

enter image description here

iOS 11, compiled with Xcode 9

enter image description here

How to get the iOS 10 behavior for devices with iOS 11 too.

like image 526
Goppinath Avatar asked Sep 01 '17 11:09

Goppinath


2 Answers

I was able to solve this problem using the answer to UITableViewCell with autolayout left margin different on iPhone and iPad. Setting “Preserve Superview Margins” on both the table view cell and the content view it contains resolved the inconsistency between rendering in iOS 10 and iOS 11.

like image 135
Alan Kantz Avatar answered Nov 01 '22 07:11

Alan Kantz


Another workaround, in the opposite direction (i.e. having the same behaviour you had in iOS 10), would be to set preservesSuperviewLayoutMargins to false in the cell and the content view of your cell. For example, in you UITableViewCell subclass:

override func awakeFromNib() {
    super.awakeFromNib()

    preservesSuperviewLayoutMargins = false
    contentView.preservesSuperviewLayoutMargins = false
}

This way you recover the iOS 10 behaviour.

like image 42
Kinopio Avatar answered Nov 01 '22 07:11

Kinopio