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

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

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

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

      swift:在导航栏中设置后退按钮图像

      时间:2023-06-12

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

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

              <tbody id='CMJRG'></tbody>

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

              <tfoot id='CMJRG'></tfoot>
              • <bdo id='CMJRG'></bdo><ul id='CMJRG'></ul>
                本文介绍了swift:在导航栏中设置后退按钮图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试在控制器的导航栏中设置后退按钮图像,这是我在 viewDidLoad() 中的代码:

                I'm trying to set the back button image in nav bar in my controller, here's my code in viewDidLoad():

                        var backImg: UIImage? = UIImage(named: "back_btn.png")
                    println(backImg)
                    if var back_img = backImg  {
                        println("GET IT")
                        println(back_img)
                        println(UIControlState.Normal)
                        println(UIBarMetrics.Default)
                    self.navigationController.navigationBar.backItem.backBarButtonItem.setBackButtonBackgroundImage(back_img, forState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
                    }
                

                我试图将它们放到 viewWillLoad 中,但得到了同样的错误

                I tried to put them to viewWillLoad, but getting the same error

                带有错误消息的控制台:

                Console with error message:

                <UIImage: 0x7ff37bd85750>
                GET IT
                <UIImage: 0x7ff37bd85750>
                VSC14UIControlState (has 1 child)
                (Enum Value)
                fatal error: unexpectedly found nil while unwrapping an Optional value
                

                我不知道哪一部分出了问题.似乎 back_img 不是 nil,但我收到错误说它是 nil

                I don't know which part went wrong. Seems like the back_img is not nil, but I got error saying it's nil

                谢谢!

                推荐答案

                我通过查看示例代码找到了答案.1)在情节提要中创建一个条形按钮项.2) 使用 IBOutlet 将该按钮链接到控制器3) 给按钮添加图片

                I have figured out by looking into sample code. 1) Create a bar button item in storyboard. 2) Link that button to controller using IBOutlet 3) Add image to the button

                 var backImg: UIImage = UIImage(named: "back_btn")
                 backBtn.setBackgroundImage(backImg, forState: .Normal, barMetrics: .Default)
                

                PS:图片应添加到 Images.xcassets 文件夹,请参阅示例代码,UICatalog,了解详情.

                PS: image should be added to Images.xcassets folder, see sample code, UICatalog , for details.

                这篇关于swift:在导航栏中设置后退按钮图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:对 &lt;UINavigationController: 0xa98e050&gt; 的开始/结束外观 下一篇:self.tabBarItem.title 不工作?

                相关文章

              • <legend id='cp6MR'><style id='cp6MR'><dir id='cp6MR'><q id='cp6MR'></q></dir></style></legend>
              • <small id='cp6MR'></small><noframes id='cp6MR'>

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