My code features UITextField and UITableView. I want my code to use AutoLayout to create a small gap between the textfield and the tableview. Right now the position of the code works well if its in iPhone mode but if it is in iPad the textfield is printed over the tableview. You can see what I am dealing with in the photo below:
hitsLabel.topAnchor.constraint(equalTo: view.centerYAnchor, constant: -250)
hitsLabel.trailingAnchor.constraint(equalTo: view.centerXAnchor, constant: 150)
hitsLabel.widthAnchor.constraint(equalToConstant: 120)
hitsLabel.heightAnchor.constraint(equalToConstant: 40)
theScores.topAnchor.constraint(equalTo: view.topAnchor, constant: 300)
theScores.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0)
theScores.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0)
theScores.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0)
I would suggest something like this:
hitsLabel.topAnchor.constraint(equalTo: view.topAnchor, constant : 100),
hitsLabel.trailingAnchor.constraint(equalTo: view.centerXAnchor, constant :150),
hitsLabel.widthAnchor.constraint(equalToConstant: 120),
hitsLabel.heightAnchor.constraint(equalToConstant: 40),
theScores.topAnchor.constraint(equalTo: hitsLabel.bottomAnchor, constant: 100),
theScores.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0),
theScores.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0),
theScores.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0),
This will place the textfield 100 pixels fromt the top of the view, and then the top of the tableView will be 100 pixels from the bottom of the textfield.
I would suggest adding constraints for the left side of the textfield as well