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

    • <bdo id='GjPJ2'></bdo><ul id='GjPJ2'></ul>

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

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

      1. 导航栏中的 iPhone 标题和副标题

        iPhone Title and Subtitle in Navigation Bar(导航栏中的 iPhone 标题和副标题)

        <small id='62waT'></small><noframes id='62waT'>

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

              <bdo id='62waT'></bdo><ul id='62waT'></ul>

            • <legend id='62waT'><style id='62waT'><dir id='62waT'><q id='62waT'></q></dir></style></legend>

                  <tbody id='62waT'></tbody>

                  本文介绍了导航栏中的 iPhone 标题和副标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我想让导航栏显示标题和副标题.

                  In my application, I'd like to have the navigation bar display a title and subtitle.

                  为此,我在视图控制器中添加了以下代码:

                  To that extent, I added the following code to my view controller:

                  // Replace titleView
                  CGRect headerTitleSubtitleFrame = CGRectMake(0, 0, 200, 44);    
                  UIView* _headerTitleSubtitleView = [[[UILabel alloc] initWithFrame:headerTitleSubtitleFrame] autorelease];
                  _headerTitleSubtitleView.backgroundColor = [UIColor clearColor];
                  _headerTitleSubtitleView.autoresizesSubviews = YES;
                  
                  CGRect titleFrame = CGRectMake(0, 2, 200, 24);  
                  UILabel *titleView = [[[UILabel alloc] initWithFrame:titleFrame] autorelease];
                  titleView.backgroundColor = [UIColor clearColor];
                  titleView.font = [UIFont boldSystemFontOfSize:20];
                  titleView.textAlignment = UITextAlignmentCenter;
                  titleView.textColor = [UIColor whiteColor];
                  titleView.shadowColor = [UIColor darkGrayColor];
                  titleView.shadowOffset = CGSizeMake(0, -1);
                  titleView.text = @"";
                  titleView.adjustsFontSizeToFitWidth = YES;
                  [_headerTitleSubtitleView addSubview:titleView];
                  
                  CGRect subtitleFrame = CGRectMake(0, 24, 200, 44-24);   
                  UILabel *subtitleView = [[[UILabel alloc] initWithFrame:subtitleFrame] autorelease];
                  subtitleView.backgroundColor = [UIColor clearColor];
                  subtitleView.font = [UIFont boldSystemFontOfSize:13];
                  subtitleView.textAlignment = UITextAlignmentCenter;
                  subtitleView.textColor = [UIColor whiteColor];
                  subtitleView.shadowColor = [UIColor darkGrayColor];
                  subtitleView.shadowOffset = CGSizeMake(0, -1);
                  subtitleView.text = @"";
                  subtitleView.adjustsFontSizeToFitWidth = YES;
                  [_headerTitleSubtitleView addSubview:subtitleView];
                  
                  _headerTitleSubtitleView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                                        UIViewAutoresizingFlexibleRightMargin |
                                                        UIViewAutoresizingFlexibleTopMargin |
                                                        UIViewAutoresizingFlexibleBottomMargin);
                  
                  self.navigationItem.titleView = _headerTitleSubtitleView;
                  

                  并且还实现了一个方法:

                  And also implemented a method:

                  -(void) setHeaderTitle:(NSString*)headerTitle andSubtitle:(NSString*)headerSubtitle {
                      assert(self.navigationItem.titleView != nil);
                      UIView* headerTitleSubtitleView = self.navigationItem.titleView;
                      UILabel* titleView = [headerTitleSubtitleView.subviews objectAtIndex:0];
                      UILabel* subtitleView = [headerTitleSubtitleView.subviews objectAtIndex:1];
                      assert((titleView != nil) && (subtitleView != nil) && ([titleView isKindOfClass:[UILabel class]]) && ([subtitleView isKindOfClass:[UILabel class]]));
                      titleView.text = headerTitle;
                      subtitleView.text = headerSubtitle;
                  }
                  

                  一切都很好,谢谢.

                  除了将iPhone旋转为横向时,标题+副标题不会像导航项的默认标题那样自动缩小.

                  Except that when rotating the iPhone to Landscape, the title+subtitle don't downsize in an automatic manner like the default title of the navigation item.

                  任何指针?

                  谢谢!

                  推荐答案

                  titleViewsubtitleView 标签变成视图控制器的属性,这样你就可以访问它们了从任何方法.然后,在视图控制器旋转时,调整标签的大小:

                  Make the titleView and subtitleView labels into properties of the view controller, so that you can access them from any method. Then, on rotation of the view controller, resize the labels:

                  - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
                      [self adjustLabelsForOrientation:toInterfaceOrientation];
                  }
                  
                  - (void) adjustLabelsForOrientation:(UIInterfaceOrientation)orientation {
                      if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
                          titleView.font = [UIFont boldSystemFontOfSize:16];
                          subtitleView.font = [UIFont boldSystemFontOfSize:11];
                      }
                      else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
                          titleView.font = [UIFont boldSystemFontOfSize:20];
                          subtitleView.font = [UIFont boldSystemFontOfSize:13];
                      }
                  }
                  

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

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

                  相关文档推荐

                  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 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设置灯光状态栏文字颜色的正确方法)
                  Show UITabBar when UIViewController pushed(推送 UIViewController 时显示 UITabBar)
                    <legend id='abHkj'><style id='abHkj'><dir id='abHkj'><q id='abHkj'></q></dir></style></legend>

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

                      <tfoot id='abHkj'></tfoot>

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

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