简体   繁体   中英

iPad: How can I add a label to the navigation bar without replacing the back button?

How can I add a label to my navigation bar that has the same font and color as the titleView text? Here's a photoshopped mockup of what I'm trying to achieve...

在此处输入图片说明

I'm using storyboards, so I tried using Interface Builder to add a UIView to the nav bar in the position that I wanted it (near the back button), then added a UILabel into that view. There were two problems with this approach. First, it made the back button go away. Second, the font and color were different than the titleView text and it was very difficult to get them to look the same.

How can I add a label (circled in red above) to the navigation bar without replacing the back button at runtime, using either Interface Builder or code?

Thanks so much in advance for your wisdom!

Although it looks super odd what you're trying to achieve, if using a UISplitController is not what you would like to do then the only other way I can think of right now is to use a UIView as the bar's titleView, set it's width to cover most of the bar.

Then use one UILabel to the left, and place one in the center. You should make the left label text align left, and the "center" label be the same width as the bar and text align it to center.

This "could" overlap, but it doesn't seem they would in your case.

As for the font, this is usually colour dark gray, with a light gray shadow offset at -1 pixel (up) and zero horizontally. And font is system bold of size 17 I believe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM