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

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

      <legend id='RtAia'><style id='RtAia'><dir id='RtAia'><q id='RtAia'></q></dir></style></legend><tfoot id='RtAia'></tfoot>
        <bdo id='RtAia'></bdo><ul id='RtAia'></ul>

      1. 以编程方式创建居中的 UIBarButton

        Creating a UIBarButton Centered Programmatically(以编程方式创建居中的 UIBarButton)

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

            <legend id='FUup0'><style id='FUup0'><dir id='FUup0'><q id='FUup0'></q></dir></style></legend>
          2. <tfoot id='FUup0'></tfoot>

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

                • <bdo id='FUup0'></bdo><ul id='FUup0'></ul>
                  本文介绍了以编程方式创建居中的 UIBarButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一组条形按钮,我通常使用以下内容进行设置:

                  I have an array of bar buttons that I normally set with something like:

                   NSArray *leftButtonArray = [[NSArray alloc]initWithObjects: backBarButton, separator1,postBarButton, separator1, memeBarButton, separator1, pollBarButton, nil];
                  self.navigationItem.leftBarButtonItems = leftButtonArray;
                  

                  但是,我想将左侧的这些按钮更改为居中对齐.有谁知道我该怎么做?提供一个例子或使用我的按钮这样做会是一个加号.

                  However, I want to change these buttons on the left to instead be center aligned. Anyone know how I can do that? Providing an example or using my buttons to do so would be a plus.

                  谢谢!

                  推荐答案

                  据我了解,您的问题需要有一些按钮在左边,一些在中间,一些在右边,并带有相对分隔符.直接导航不会提供把按钮放在中间,或者在TitleView中

                  As I understand your problem it required to have some button to left, some on middle, and some on right with relative separator. Directly navigation will not provide to put button is middle, or in TitleView

                  您可以像这样为导航栏设置自定义标题视图.

                  You can set custom title view to the navigation bar like this way.

                  //To hide default back button
                  self.navigationItem.hidesBackButton=YES;
                  
                  //Title View for Navigation
                  UIView *navTitle1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
                  [navTitle1 setBackgroundColor:[UIColor lightGrayColor]];
                  
                  //Left View button and separator
                  UIButton *backBarButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 44)];
                  [backBarButton setTitle:@"Back" forState:UIControlStateNormal];
                  
                  UIView *ttlview1 = [[UIView alloc] initWithFrame:CGRectMake(51, 0, 1, 44)];
                  [ttlview1 setBackgroundColor:[UIColor darkGrayColor]];
                  
                  
                  //Center view with two buttons and seprator for them
                  UIView *middleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 121, 44)];
                  [middleView setBackgroundColor:[UIColor clearColor]];
                  [middleView setCenter:navTitle1.center];
                  
                  UIButton *postBarButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
                  [postBarButton setTitle:@"Post" forState:UIControlStateNormal];
                  
                  UIView *ttlview2 = [[UIView alloc] initWithFrame:CGRectMake(middleView.frame.size.width/2, 0, 1, 44)];
                  [ttlview2 setBackgroundColor:[UIColor darkGrayColor]];
                  
                  UIButton *memeBarButton = [[UIButton alloc] initWithFrame:CGRectMake((middleView.frame.size.width/2)+1, 0, 60, 44)];
                  [memeBarButton setTitle:@"Meme" forState:UIControlStateNormal];
                  
                  [middleView addSubview:ttlview2];
                  [middleView addSubview:postBarButton];
                  [middleView addSubview:memeBarButton];
                  
                  //Right button with seprator before that
                  UIView *ttlview3 = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width-71, 0, 1, 44)];
                  [ttlview3 setBackgroundColor:[UIColor darkGrayColor]];
                  
                  UIButton *pollBarButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-70, 0, 50, 44)];
                  [pollBarButton setTitle:@"POLL" forState:UIControlStateNormal];
                  
                  [navTitle1 addSubview:backBarButton];
                  [navTitle1 addSubview:ttlview1];
                  [navTitle1 addSubview:middleView];
                  [navTitle1 addSubview:ttlview3];
                  [navTitle1 addSubview:pollBarButton];
                  self.navigationItem.titleView = navTitle1;
                  

                  看起来像,这个

                  也许这会对你有所帮助.

                  May be this would help you.

                  HTH,享受编码!

                  这篇关于以编程方式创建居中的 UIBarButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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设置灯光状态栏文字颜色的正确方法)
                  <tfoot id='cfq1J'></tfoot>

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

                  1. <small id='cfq1J'></small><noframes id='cfq1J'>

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

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