Search code examples
objective-cios11iphone-xsafearealayoutguide

UITableview merging with the home indicator on iPhone X


I have a UITableView created programmatically. This UITableView merges with the home indicator on an iPhone X device.

How can I fix this issue?

enter image description here


Solution

  • Programatically, set bottom anchor of tableview with bottom anchor of SafeAreaLayout.

    Here is sample/test code, how to programatically set safe area layout with respect to interface elements.

    if #available(iOS 11, *) {
      let guide = view.safeAreaLayoutGuide
      NSLayoutConstraint.activate([
       table.topAnchor.constraintEqualToSystemSpacingBelow(guide.topAnchor, multiplier: 1.0),
       guide.bottomAnchor.constraintEqualToSystemSpacingBelow(table.bottomAnchor, multiplier: 1.0)
       ])
    
    } else {
       let standardSpacing: CGFloat = 8.0
       NSLayoutConstraint.activate([
       table.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 0),
       bottomLayoutGuide.topAnchor.constraint(equalTo: table.bottomAnchor, constant: 0)
       ])
    }
    

    Here are useful references (answers):