Currently, on iPad, my UINavigationBar large title looks strange because it does not indent to where my UITableView cells are. This is because my table view and cells follow readable width. Is there a way of indenting this title or is the only piece of advice to align the cells with the title (make them not follow readable width). I would really appreciate anyone who took the time to respond.
When you first load your view controller, you should retrieve the minX
coordinate of the current readableContentGuide
and set that value to the left layoutMargin
value. As so:
let leftMargin = self.view.readableContentGuide.layoutFrame.minX
self.navigationController?.navigationBar.layoutMargins.left = leftMargin
Then, you'll also want to make sure your layout adjusts dynamically so that if the user rotates their screen (or on an iPad, is using a variable window size) the title will remain aligned:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { _ in
let leftMargin = view.readableContentGuide.layoutFrame.minX
navigationController?.navigationBar.layoutMargins.left = leftMargin
}, completion: nil)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With