I'm trying to mimic the look of UINavigationBar
as used by the Apple Music App (the date is shown above the large title).
I know that the Apple Music App doesn't use the standard UINavigationBar
of ios11 but a header view is UICollectionView
.
I also want to use the standard UINavigationBar
of ios11 because of the resizing feature for title text.
I'm able to add the custom date label
to view hierarchy of the large title view
, my code as shown below:
self.title = "Large Title"
navigationController?.navigationBar.prefersLargeTitles = true
guard let navigationBar = navigationController?.navigationBar else { return }
// Create label
let label = UILabel()
label.text = "Small Title"
// Add label to subview hierarchy
for subview in navigationBar.subviews {
let stringFromClass = NSStringFromClass(subview.classForCoder)
if stringFromClass.contains("UINavigationBarLargeTitleView") {
subview.addSubview(label)
}
}
// Add label constraints
label.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
label.leftAnchor.constraint(equalTo: navigationBar.leftAnchor, constant: 16.0),
label.bottomAnchor.constraint(equalTo: navigationBar.bottomAnchor, constant: -50.0),
label.heightAnchor.constraint(equalToConstant: 20.0),
label.widthAnchor.constraint(equalToConstant: 200.0)
])
The custom date label
is placed correctly but I'm unable to set the height of UINavigationBar
to additional height
of the label.
Since ios11 UINavigationBar
uses Auto-layout, so setting the frame wont work anymore as like the previous iOS versions.
The Auto-layout constraints added by the system. by default it have a priority of 1000, so adding the additional constraints to the label didn't give any effect or result in the Auto-layout conflict.
Any hints to show the "Small Title" above the "Large Title" without scrolling?