How to move the sliding position below the title or the position of the back button

I would like to have a big headline with a little text under it without pressing the back button.

Desired Result:

enter image description here

With a tip and a caption:

I set the time as a name, which is the opposite of what I want to put the name at the beginning

enter image description here

With custom navigationItem.titleView :

enter image description hereenter image description here

In the second photo, I add height to the navigationBar . This is very close to what I would like, but I want the back button to stay on top. I can simply change the limitations of my custom titleView if I can move the back button.

Current code:

 func createTitleView() { let titleView = UIView() let titleLabel = UILabel() titleLabel.text = "Pete Diner" titleLabel.textColor = UIColor.whiteColor() titleLabel.font = UIFont.boldSystemFontOfSize(16.0) titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false) let descLabel = UILabel() descLabel.text = "Open 9AM - 9PM" descLabel.textColor = UIColor.whiteColor() descLabel.font = UIFont.systemFontOfSize(14.0) descLabel.setTranslatesAutoresizingMaskIntoConstraints(false) titleView.addSubview(titleLabel) titleView.addSubview(descLabel) titleView.addConstraint(NSLayoutConstraint( item: titleView, attribute: .CenterX, relatedBy: .Equal, toItem: titleLabel, attribute: .CenterX, multiplier: 1.0, constant: 0)) titleView.addConstraint(NSLayoutConstraint( item: titleView, attribute: .CenterX, relatedBy: .Equal, toItem: descLabel, attribute: .CenterX, multiplier: 1.0, constant: 0)) titleView.addConstraint(NSLayoutConstraint( item: titleView, attribute: NSLayoutAttribute.CenterYWithinMargins, relatedBy: NSLayoutRelation.Equal, toItem: titleLabel, attribute: NSLayoutAttribute.CenterYWithinMargins, multiplier: 1.0, constant: 12)) titleView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat( "V:[titleLabel]-2-[descLabel]", options: nil, metrics: nil, views: ["titleLabel": titleLabel, "descLabel": descLabel])) navigationItem.titleView = titleView let nav = navigationController?.navigationBar nav!.barTintColor = UIColor.customGreenColor() nav!.tintColor = UIColor.whiteColor() nav!.translucent = false nav!.frame.size.height = 60.0 } 

Side panel:

Limitations are not set up to ~ 500 ms after the appearance of the view. I tried setting titleView to viewDidLayoutSubviews , which doesn't help. If anyone can help me, I will be grateful. I think this is the navigationBar / custom titleView problem.

+6
source share
1 answer

I solved this by adding a custom top view to the view, and then add a shortcut to it, which will be used as the subtitle label.

Having made this custom dock to the bottom of the navigation bar, expand the entire width of the screen and change its height to the font size of the label, as well as the upper and lower margins on the label, the view will be tightly located under the navigation panel.

Then you must adjust the navigation bar and user view to the same background color, and then remove the shadow image for the navigation bar.

0
source

Source: https://habr.com/ru/post/988798/


All Articles