<tfoot id='cYvGo'></tfoot>
  • <legend id='cYvGo'><style id='cYvGo'><dir id='cYvGo'><q id='cYvGo'></q></dir></style></legend>

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

        <bdo id='cYvGo'></bdo><ul id='cYvGo'></ul>

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

        子类化 UINavigationBar ...如何在 UINavigationController 中使用它?

        Subclassing UINavigationBar ... how do I use it in UINavigationController?(子类化 UINavigationBar ...如何在 UINavigationController 中使用它?)

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

              <bdo id='oXkYz'></bdo><ul id='oXkYz'></ul>

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

                1. <i id='oXkYz'><tr id='oXkYz'><dt id='oXkYz'><q id='oXkYz'><span id='oXkYz'><b id='oXkYz'><form id='oXkYz'><ins id='oXkYz'></ins><ul id='oXkYz'></ul><sub id='oXkYz'></sub></form><legend id='oXkYz'></legend><bdo id='oXkYz'><pre id='oXkYz'><center id='oXkYz'></center></pre></bdo></b><th id='oXkYz'></th></span></q></dt></tr></i><div id='oXkYz'><tfoot id='oXkYz'></tfoot><dl id='oXkYz'><fieldset id='oXkYz'></fieldset></dl></div>
                2. <tfoot id='oXkYz'></tfoot>
                    <tbody id='oXkYz'></tbody>
                  本文介绍了子类化 UINavigationBar ...如何在 UINavigationController 中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想继承 UINavigationBar(设置自定义背景图像和文本颜色)并将其用于我应用程序中的所有导航栏.查看 UINavigationController 的 API 文档,看起来 navigationBar 是只读的:

                  I wanted to subclass UINavigationBar (to set a custom background image & text color) and use that for all the navigation bars in my app. Looking at the API docs for UINavigationController, it looks like navigationBar is read-only:

                  @property(nonatomic, readonly) UINavigationBar *navigationBar

                  @property(nonatomic, readonly) UINavigationBar *navigationBar

                  有没有办法在我的 UIViewControllers 中实际使用自定义 UINavigationBar?我知道其他应用已经做了自定义导航栏,比如 flickr:

                  Is there a way to actually use a custom UINavigationBar in my UIViewControllers? I know that other apps have done custom navigation bars, like flickr:

                  http://img.skitch.com/20100520-bpxjaca11h5xne5yakjdc2m6xx.png

                  这是我的 UINavigationBar 子类:

                  Here is my UINavigationBar subclass:

                  #import <UIKit/UIKit.h>
                  
                  @interface MyNavigationBar : UINavigationBar <UINavigationBarDelegate> {
                  
                  }
                  
                  @end
                  

                  实现

                  #import "MyNavigationBar.h"
                  
                  @implementation MyNavigationBar
                  
                  - (id)initWithFrame:(CGRect)frame {
                      if (self = [super initWithFrame:frame]) {
                          // Initialization code
                      }
                      return self;
                  }
                  
                  - (void)drawRect:(CGRect)rect {
                      // override the standard background with our own custom one
                      UIImage *image = [[UIImage imageNamed:@"navigation_bar_bgd.png"] retain];
                      [image drawInRect:rect];
                      [image release];
                  }
                  
                  #pragma mark -
                  #pragma mark UINavigationDelegate Methods
                  
                  - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
                      // use the title of the passed in view controller
                      NSString *title = [viewController title];
                  
                      // create our own UILabel with custom color, text, etc
                      UILabel *titleView = [[UILabel alloc] init];
                      [titleView setFont:[UIFont boldSystemFontOfSize:18]];
                      [titleView setTextColor:[UIColor blackColor]];
                      titleView.text = title;
                      titleView.backgroundColor = [UIColor clearColor];
                      [titleView sizeToFit];
                  
                      viewController.navigationItem.titleView = titleView;
                      [titleView release];
                  
                      viewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:0.8];
                  }
                  - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
                  }
                  
                  
                  - (void)dealloc {
                      [super dealloc];
                  }
                  
                  @end
                  

                  我知道我可以使用一个类别来改变背景图片,但我仍然希望能够设置导航栏标题的文本颜色

                  I know that I can use a category to change the background image, but i still want to be able to set the text color of the navigation bar title

                  @implementation UINavigationBar (CustomImage)
                  - (void)drawRect:(CGRect)rect {
                      UIImage *image = [UIImage imageNamed: @"navigation_bar_bgd.png"];
                      [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
                  }
                  @end
                  

                  有什么建议或其他解决方案吗?我基本上想创建像 Flickr 的应用导航栏这样的浅色背景和深色文本

                  any suggestions or other solutions? I basically want to create a light background and dark text like Flickr's app navigation bars

                  推荐答案

                  我不知道你是否明白这一点.但是对于其他可能有这个问题的人......

                  I dunno if you got this figured out. But for others that might have this problem...

                  您需要做的是在您的 XIB 中将类指定为您的类名(在本例中为 MyNavigationBar.

                  What you need to do is to specify the class in your XIB to your class name (in this case MyNavigationBar.

                  查看 WWDC 2011 中的会话 123.

                  Check session 123 in WWDC 2011.

                  这篇关于子类化 UINavigationBar ...如何在 UINavigationController 中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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)

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

                        <tfoot id='NAP9T'></tfoot><legend id='NAP9T'><style id='NAP9T'><dir id='NAP9T'><q id='NAP9T'></q></dir></style></legend>
                          <bdo id='NAP9T'></bdo><ul id='NAP9T'></ul>
                        • <small id='NAP9T'></small><noframes id='NAP9T'>

                            <tbody id='NAP9T'></tbody>