<i id='g9c57'><tr id='g9c57'><dt id='g9c57'><q id='g9c57'><span id='g9c57'><b id='g9c57'><form id='g9c57'><ins id='g9c57'></ins><ul id='g9c57'></ul><sub id='g9c57'></sub></form><legend id='g9c57'></legend><bdo id='g9c57'><pre id='g9c57'><center id='g9c57'></center></pre></bdo></b><th id='g9c57'></th></span></q></dt></tr></i><div id='g9c57'><tfoot id='g9c57'></tfoot><dl id='g9c57'><fieldset id='g9c57'></fieldset></dl></div>
      <legend id='g9c57'><style id='g9c57'><dir id='g9c57'><q id='g9c57'></q></dir></style></legend>
      <tfoot id='g9c57'></tfoot>
        <bdo id='g9c57'></bdo><ul id='g9c57'></ul>
      1. <small id='g9c57'></small><noframes id='g9c57'>

      2. UINavigationItem 居中标题

        UINavigationItem centering the title(UINavigationItem 居中标题)

          <tbody id='JnYeB'></tbody>
          <bdo id='JnYeB'></bdo><ul id='JnYeB'></ul>

            <small id='JnYeB'></small><noframes id='JnYeB'>

          • <tfoot id='JnYeB'></tfoot>

            <legend id='JnYeB'><style id='JnYeB'><dir id='JnYeB'><q id='JnYeB'></q></dir></style></legend>

                <i id='JnYeB'><tr id='JnYeB'><dt id='JnYeB'><q id='JnYeB'><span id='JnYeB'><b id='JnYeB'><form id='JnYeB'><ins id='JnYeB'></ins><ul id='JnYeB'></ul><sub id='JnYeB'></sub></form><legend id='JnYeB'></legend><bdo id='JnYeB'><pre id='JnYeB'><center id='JnYeB'></center></pre></bdo></b><th id='JnYeB'></th></span></q></dt></tr></i><div id='JnYeB'><tfoot id='JnYeB'></tfoot><dl id='JnYeB'><fieldset id='JnYeB'></fieldset></dl></div>
                  本文介绍了UINavigationItem 居中标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个导航栏,每侧都有左右栏按钮.我有一个 customTitlelabel,我将它设置为 UINavigationItem 的 titleView.

                  I have a navigationBar with both Left and Right bar buttons on each side. I have a customTitlelabel which I set as the titleView of the UINavigationItem.

                  [self.navigationItem setTitleView:customTitleLabel];

                  [self.navigationItem setTitleView:customTitleLabel];

                  现在一切都很好.问题是,rightbarButton 的大小是动态的,基于我在其中一个文本字段中获得的输入.

                  All is fine now. The problem, the size of the rightbarButton is dynamic based on the input I get in one of the text fields.

                  因此,标题会根据按钮之间的可用空间自动居中.

                  Therefore the title is automatically centered based on the available space between the buttons.

                  如何将标题设置为固定位置?

                  how can i set the title to a fixed position?

                  推荐答案

                  你不能直接做你想做的——你的标题视图的位置是你无法控制的(当由 UINavigationBar).

                  You can't do what you want directly -- the position of your title view is out of your control (when managed by UINavigationBar).

                  不过,至少有两种策略可以达到你想要的效果:

                  However, there are at least two strategies to get the effect you want:

                  1) 添加标题视图不是作为导航栏的正确"标题视图,而是作为 UINavigationBar 的子视图.(注意:这不是官方"批准的,但我已经看到它完成了,并且有效.显然你必须注意你的标题标签覆盖按钮的位,并为不同的方向处理不同大小的导航栏等.-- 有点繁琐.)

                  1) Add the title view not as the 'proper' title view of the nav bar, but as a subview of the UINavigationBar. (Note: this is not 'officially' sanctioned, but I've seen it done, and work. Obviously you have to watch out for your title label overwriting bits of the buttons, and handle different size nav bars for different orientations, etc. -- a bit fiddly.)

                  2) 创建一个智能 UIView 子类,在计算出的位置显示给定的子视图(这将是您的 UILabel),以有效地显示子视图在屏幕上完美居中.为此,您的智能 UIView 子类将通过更改标签子视图的位置 (frame) 来响应布局事件(或 frame 属性更改等).

                  2) Make an intelligent UIView subclass that displays a given subview (which would be your UILabel) at a position calculated to effectively show the subview perfectly centered on the screen. In order to do this, your intelligent UIView subclass would respond to layout events (or frame property changes etc.) by changing the position (frame) of the label subview.

                  就个人而言,我最喜欢方法 2) 的想法.

                  Personally, I like the idea of approach 2) the best.

                  这篇关于UINavigationItem 居中标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  UINavigationController inside a UITabBarController inside a UISplitViewController presented modally on iPhone(UISplitViewController 内的 UITabBarController 内的 UINavigationController 以模态方式呈现在 iPhone 上) - IT屋-程序员软件开发技术分
                  ViewController in UINavigationController orientation change(UINavigationController 中的 ViewController 方向更改)
                  Custom back button in UINavigationController(UINavigationController 中的自定义后退按钮)
                  How to add a navigation controller programmatically in code but not as initial view controller(如何在代码中以编程方式添加导航控制器,但不作为初始视图控制器)
                  How to get the previous viewcontroller that pushed my current view(如何获取推送我当前视图的上一个视图控制器)
                  The correct way to set a light status bar text color in iOS 7 based on different ViewControllers(iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法)

                        <tbody id='cesY5'></tbody>

                      <small id='cesY5'></small><noframes id='cesY5'>

                      <legend id='cesY5'><style id='cesY5'><dir id='cesY5'><q id='cesY5'></q></dir></style></legend>
                      <tfoot id='cesY5'></tfoot>

                    • <i id='cesY5'><tr id='cesY5'><dt id='cesY5'><q id='cesY5'><span id='cesY5'><b id='cesY5'><form id='cesY5'><ins id='cesY5'></ins><ul id='cesY5'></ul><sub id='cesY5'></sub></form><legend id='cesY5'></legend><bdo id='cesY5'><pre id='cesY5'><center id='cesY5'></center></pre></bdo></b><th id='cesY5'></th></span></q></dt></tr></i><div id='cesY5'><tfoot id='cesY5'></tfoot><dl id='cesY5'><fieldset id='cesY5'></fieldset></dl></div>
                          • <bdo id='cesY5'></bdo><ul id='cesY5'></ul>