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

  • <legend id='tbAdz'><style id='tbAdz'><dir id='tbAdz'><q id='tbAdz'></q></dir></style></legend>
      <bdo id='tbAdz'></bdo><ul id='tbAdz'></ul>

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

        <tfoot id='tbAdz'></tfoot>

        垂直对齐 UINavigationItems

        vertically aligning UINavigationItems(垂直对齐 UINavigationItems)
          <tbody id='Na98w'></tbody>
      2. <legend id='Na98w'><style id='Na98w'><dir id='Na98w'><q id='Na98w'></q></dir></style></legend>

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

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

                1. 本文介绍了垂直对齐 UINavigationItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  I have customized the UINavigationBar's height to 100px and I'd like to add buttons onto this customized bar.

                  All is good except the button seems to want to sit on the bottom of the nav bar no matter what. I can't get it to align to the center or the top of the nav bar.

                  Here is the code; first I create a navigation controller in the app delegate and add one button on the right.

                  // set main navigation controller
                  temp *tempc = [[temp alloc] initWithNibName:@"temp" bundle:nil];
                  self.navigationController = [[UINavigationController alloc] initWithRootViewController:tempc];
                  
                  UIBarButtonItem *navItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
                  
                  [tempc.navigationItem setRightBarButtonItem:navItem];
                  [self.window addSubview:self.navigationController.view];
                  [self.window makeKeyAndVisible];
                  

                  then I resize the navigation bar in the "temp" view controller like so:

                  - (void)viewDidAppear:(BOOL)animated
                  {
                      [super viewDidAppear:animated];
                      CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 100.0f);
                      [self.navigationController.navigationBar setFrame:frame];
                      [self.navigationController.navigationBar setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];
                  }
                  

                  I've also tried to add a custom view to the rightBarButtonItem but I can't get the added custom view to touch the top completely.

                  And the code for this unfortunate attempt:

                  // set main navigation controller
                  temp *tempc = [[temp alloc] initWithNibName:@"temp" bundle:nil];
                  self.navigationController = [[UINavigationController alloc] initWithRootViewController:tempc];
                  
                  UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 36.0f, 80.0f)];
                  [customView setBackgroundColor:[UIColor blueColor]];
                  
                  UIButton *customButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                  [customButton setFrame:CGRectMake(0, 22.0f, 36.0f, 36.0f)];
                  [customButton setTitle:@"+" forState:UIControlStateNormal];
                  
                  [customView addSubview:customButton];
                  UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:customView];
                  

                  Does anyone know how to vertically align UIBarButtonItems on a UINavigationBar?

                  解决方案

                  Option 1:

                  • create UINavigationBar subclass
                  • inside this class override - (void)layoutSubviews where you will reposition UIBarButtonItems
                  • in Interface Builder set UINavigationBar class to UINavigationBar subclass

                  Example:

                  inside subclass of UINavigationBar:

                  - (void)layoutSubviews {
                      int index = 0;
                      for ( UIButton *button in [self subviews] ) {
                          if(index == 1) {
                              [button setFrame:CGRectMake(5,40,60,40)]; //leftBarButtonItem
                          } else if(index == 2) {
                              [button setFrame:CGRectMake(275,40,40,40)]; //rightBarButtonItem
                          }
                          ++index;
                      }
                  }
                  

                  view controller:

                  - (void)viewDidLoad {
                  ...
                      UIBarButtonItem *navItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
                      UIBarButtonItem *navItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:nil action:nil];
                      [self.navigationItem setRightBarButtonItem:navItem1];   
                      [self.navigationItem setLeftBarButtonItem:navItem2];
                  
                      CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 100.0f);
                      [self.navigationController.navigationBar setFrame:frame];
                  ...
                  }
                  

                  Option 2 (inserting UIBarButtonItem doesn't work):

                  UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0,320,100)];
                  [self.view addSubview:navigationBar];
                  
                  UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                  [button setFrame:CGRectMake(0,25,50,50)];
                  [navigationBar addSubview:button];
                  

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

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

                  相关文档推荐

                  iOS 6 rotations: supportedInterfaceOrientations doesn#180;t work?(iOS 6 旋转:supportedInterfaceOrientations 不起作用?)
                  CABasicAnimation rotate returns to original position(CABasicAnimation 旋转返回原始位置)
                  UITabBarController Rotation Issues in ios 6(ios 6 中的 UITabBarController 旋转问题)
                  iOS: How to run a function after Device has Rotated (Swift)(iOS:设备旋转后如何运行函数(Swift))
                  How to rotate an image 90 degrees on iOS?(如何在 iOS 上将图像旋转 90 度?)
                  iOS 8 Rotation Methods Deprecation - Backwards Compatibility(iOS 8 旋转方法弃用 - 向后兼容性)

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

                    • <legend id='IpLc4'><style id='IpLc4'><dir id='IpLc4'><q id='IpLc4'></q></dir></style></legend>

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

                            <tfoot id='IpLc4'></tfoot>