I have simple UITableView
inside UIViewController
. Here is configurations and constraints I set:
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.insetsContentViewsToSafeArea = false
view.addSubview(tableView)
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
tableView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
By doing this, I canceled safeArea in UITableView and set top, bottom constrains ignoring safeAreaLayoutGuide
. Yes, it perfectly works when I scroll by table and safe area is ignored as I want. Here is image showing this:
But the problem is at the beginning when I don't start scrolling or touching table. It starts below safe area, not out of safe area. Here it is:
I don't want it to happen. I want my UITableView
(or first UITableViewCell
) from the uppermost point ignoring safe area. It seems UITableView
ignores this even if I set constraints correctly. So, how to solve this problem?
You need to also set the tableView
's contentInsetAdjustmentBehavior
:
tableView.contentInsetAdjustmentBehavior = .never