I have a table view and inside that I have added a cell which has label on the right side of of the view.
But when I am running the application, this is what I get. (It is being run on iPhone 6S):
As you can see, the label is being pushed out.
The result on iPhone XR are fine. Here is the screenshot for XR:
Here is the code for the view controller where the table view delegates are:
import UIKit
class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
tableView.separatorStyle = .none
let headerViewNibName = UINib(nibName: "HeaderCell", bundle: nil)
tableView.register(headerViewNibName, forCellReuseIdentifier: "headerCell")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell", for: indexPath) as! HeaderCell
cell.isUserInteractionEnabled = false
return cell
}
return UITableViewCell()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
return 138
}
return 0
}
}
Can someone please explain why this is happening?
Edit:
Attaching screenshot for cell view with constraints visible: