• <small id='Sa6qy'></small><noframes id='Sa6qy'>

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

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

        自定义 UINavigationController UIToolbar 背景图片

        Custom UINavigationController UIToolbar Background Image(自定义 UINavigationController UIToolbar 背景图片)
          <i id='FyFgL'><tr id='FyFgL'><dt id='FyFgL'><q id='FyFgL'><span id='FyFgL'><b id='FyFgL'><form id='FyFgL'><ins id='FyFgL'></ins><ul id='FyFgL'></ul><sub id='FyFgL'></sub></form><legend id='FyFgL'></legend><bdo id='FyFgL'><pre id='FyFgL'><center id='FyFgL'></center></pre></bdo></b><th id='FyFgL'></th></span></q></dt></tr></i><div id='FyFgL'><tfoot id='FyFgL'></tfoot><dl id='FyFgL'><fieldset id='FyFgL'></fieldset></dl></div>
              • <bdo id='FyFgL'></bdo><ul id='FyFgL'></ul>

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

                  <tbody id='FyFgL'></tbody>

                  <legend id='FyFgL'><style id='FyFgL'><dir id='FyFgL'><q id='FyFgL'></q></dir></style></legend>
                1. <tfoot id='FyFgL'></tfoot>
                2. 本文介绍了自定义 UINavigationController UIToolbar 背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用 UINavigationController 的 iPhone 应用程序,并希望使用自定义背景图像自定义元素.我可以很容易地使用如下的 Objective-C 类别为 UINavigationController's UINavigationBar 做到这一点:

                  I have an iPhone application using UINavigationController and would like to customize the elements with custom background images. I was able to do this for the UINavigationController's UINavigationBar pretty easily using Objective-C categories as below:

                  http://foobarpig.com/iphone/uinavigationbar-with-solid-color-or-image-background.html

                  我想对 UINavigationController 的 UIToolbar 做同样的事情,但同样的方法似乎不起作用(尽管我完全不知道为什么不这样做.) 我环顾四周,人们似乎建议子类化 UIToolbar,但这对于 UINavigationController 的 工具栏是不可能的,它是一个只读 UIToolbar.我想使用 UINavigationController's 工具栏而不是仅仅制作子视图工具栏,因为我使用的是滑入式 setToolbarHidden 动画.

                  I'd like to do the same for the UINavigationController's UIToolbar, but the same approach doesn't seem to work (although I have absolutely no idea why not.) I've looked around and people seem to suggest subclassing UIToolbar, but this isn't possible for the UINavigationController's toolbar, which is a read-only UIToolbar. I want to use the UINavigationController's toolbar instead of just making a subview toolbar because I'm using the slide-in setToolbarHidden animation.

                  任何人都知道是否可以将背景图像应用到这个 UINavigationController 工具栏(很可能通过某种方式覆盖 drawRect 方法)?

                  Anyone have any idea if it's possible to apply a background image to this UINavigationController toolbar (most likely by somehow overriding the drawRect method)?

                  推荐答案

                  你需要子类而不是创建一个类别.

                  You need to subclass instead of creating a category.

                  我不太清楚为什么一个类别适用于 UINavigationBar 而不是 UIToolbar,但子类化适用于它们,我认为这是更标准的自定义方式类似的东西.

                  I'm not too sure why a category works for UINavigationBar but not UIToolbar, but subclassing works for both of them and I think it's the more standard way of customizing stuff like that.

                  所以要继承 UIToolbar,创建一个名为 MyToolbar 的类(或类似的东西)并将其放在 .h 中:

                  So to subclass UIToolbar, create a class called MyToolbar (or something similar) and put this in the .h:

                  #import <UIKit/UIKit.h>
                  #import <Foundation/Foundation.h>
                  
                  @interface MyToolbar : UIToolbar {}
                  
                  - (void)drawRect:(CGRect)rect;
                  
                  @end
                  

                  这在 .m 文件中:

                  #import "MyToolbar.h"
                  
                  @implementation MyToolbar
                  
                  - (void)drawRect:(CGRect)rect {
                      backgroundImage = [UIImage imageNamed:@"my-awesome-toolbar-image.png"];
                      [backgroundImage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
                  }
                  
                  @end
                  

                  从那里你必须告诉导航控制器使用 MyToolbar 而不是 UIToolbar.我发现最简单的方法是在 Interface Builder 中选择您的 Navigation Controller,然后在 Attributes Inspector 中选中Shows Toolbar"框.工具栏应显示在 NavigationController 窗口中.单击它,然后在 Identity Inspector 中将类更改为 MyToolbar.

                  From there you've got to tell the Navigation Controller to use MyToolbar instead of UIToolbar. Easiest way I've found to do that is to select your Navigation Controller in Interface Builder, then in the Attributes Inspector check the 'Shows Toolbar' box. The toolbar should show up in the NavigationController window. Click on it and then in the Identity Inspector change the class to MyToolbar.

                  这篇关于自定义 UINavigationController UIToolbar 背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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设置灯光状态栏文字颜色的正确方法)
                  View being blocked by UITransitionView after being presented(呈现后被 UITransitionView 阻止的视图)

                    <tfoot id='C1rzJ'></tfoot>

                      <bdo id='C1rzJ'></bdo><ul id='C1rzJ'></ul>
                    • <small id='C1rzJ'></small><noframes id='C1rzJ'>

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

                              <tbody id='C1rzJ'></tbody>