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

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

    1. <tfoot id='XOU0E'></tfoot>

        更改 UINavigationBar 背景图像

        时间:2023-05-17
          <tbody id='mtNa7'></tbody>

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

            <tfoot id='mtNa7'></tfoot>

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

                <i id='mtNa7'><tr id='mtNa7'><dt id='mtNa7'><q id='mtNa7'><span id='mtNa7'><b id='mtNa7'><form id='mtNa7'><ins id='mtNa7'></ins><ul id='mtNa7'></ul><sub id='mtNa7'></sub></form><legend id='mtNa7'></legend><bdo id='mtNa7'><pre id='mtNa7'><center id='mtNa7'></center></pre></bdo></b><th id='mtNa7'></th></span></q></dt></tr></i><div id='mtNa7'><tfoot id='mtNa7'></tfoot><dl id='mtNa7'><fieldset id='mtNa7'></fieldset></dl></div>
                  本文介绍了更改 UINavigationBar 背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我一直在尝试更改我的应用程序 UINavigationBar 的背景图像.我尝试了几种方法.首先,我在我的 AppDelegate 类中添加了以下代码:

                  I've been trying to change the background image of the UINavigationBar of my application. I tried several ways. First I added to my AppDelegate class the following code:

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

                  但它不起作用.我的下一个尝试是编写一个覆盖 drawRect 方法的 CustomizedNavigationBar 类.看起来是这样的:

                  But it wasn't working. My next try was to write a CustomizedNavigationBar Class which is overriding the drawRect method. It looked like that:

                  CustomizedNavigationBar.h

                  #import <UIKit/UIKit.h>
                  
                  @interface CustomizedNavigationBar : UINavigationBar
                  
                  @end
                  

                  CustomizedNavigationBar.m

                  #import "CustomizedNavigationBar.h"
                  
                  @implementation CustomizedNavigationBar
                  
                  - (void) drawRect:(CGRect)rect {
                      UIImage *image = [UIImage imageNamed: @"navigationbar.png"];
                      [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
                  
                      NSLog(@"I got called!!!!!");
                  }
                  
                  @end
                  

                  在定义 NavigationBar 的 .xib 文件中,我将类更改为新的 CustomizedNavigationBar.但它仍然无法正常工作..

                  In my .xib file where the NavigationBar is defined I changed the class to the new CustomizedNavigationBar. But still it is not working..

                  作为另一个测试,我下载了一个应该更改背景图像的示例项目.但即使使用该示例代码,它也无法正常工作.

                  As another test I downloaded an example project where the background image should be changed. But even with that sample code it was not working.

                  我做错了什么?我正在使用 IOS 5.我可以定义背景图像的任何建议或其他方式?

                  What am I doing wrong? I am using IOS 5. Any suggestions or other ways I could define a background image?

                  感谢您的回答!

                  推荐答案

                  从 iOS 5 开始你应该使用 -setBackgroundImage:forBarMetrics: 方法:

                  Starting in iOS 5 you should use the -setBackgroundImage:forBarMetrics: method:

                  [myNavbar setBackgroundImage:[UIImage imageNamed: @"UINavigationBarBackground.png"] 
                                 forBarMetrics:UIBarMetricsDefault];
                  

                  Swift 4 中:

                  navigationBar.setBackgroundImage(UIImage(named: "UINavigationBarBackground.png"),
                                 for: .default)
                  

                  这篇关于更改 UINavigationBar 背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Swift 中禁用向后滑动手势 下一篇:如何动态调整导航栏中标题的大小

                  相关文章

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

                    <tfoot id='3SiXn'></tfoot>

                      <bdo id='3SiXn'></bdo><ul id='3SiXn'></ul>

                      <legend id='3SiXn'><style id='3SiXn'><dir id='3SiXn'><q id='3SiXn'></q></dir></style></legend>

                      <small id='3SiXn'></small><noframes id='3SiXn'>