<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 中使用它?

        时间:2023-06-11

          <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 中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:加载 MKMapView 时崩溃 下一篇:如何创建像 BestBuy App 这样的自定义导航栏?

                  相关文章

                  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>
                  2. <small id='NAP9T'></small><noframes id='NAP9T'>