• <legend id='c8M7h'><style id='c8M7h'><dir id='c8M7h'><q id='c8M7h'></q></dir></style></legend>

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

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

      1. <i id='c8M7h'><tr id='c8M7h'><dt id='c8M7h'><q id='c8M7h'><span id='c8M7h'><b id='c8M7h'><form id='c8M7h'><ins id='c8M7h'></ins><ul id='c8M7h'></ul><sub id='c8M7h'></sub></form><legend id='c8M7h'></legend><bdo id='c8M7h'><pre id='c8M7h'><center id='c8M7h'></center></pre></bdo></b><th id='c8M7h'></th></span></q></dt></tr></i><div id='c8M7h'><tfoot id='c8M7h'></tfoot><dl id='c8M7h'><fieldset id='c8M7h'></fieldset></dl></div>
        <tfoot id='c8M7h'></tfoot>
      2. 为栏按钮项目设置图像和标题?

        时间:2023-05-17

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

            <small id='8DLJT'></small><noframes id='8DLJT'>

            <legend id='8DLJT'><style id='8DLJT'><dir id='8DLJT'><q id='8DLJT'></q></dir></style></legend>

                  本文介绍了为栏按钮项目设置图像和标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我目前有一个自定义导航控制器,其中包含简单的文本按钮的条形按钮项.是否可以保留栏按钮项目的标题,但也可以将它们设置为图像(图标图像+标题下方).

                  I currently have a custom navigation controller with bar button items that are simply text buttons. Is it possible to keep the title of the bar button items but also set them as images (icon image + title underneath).

                  class NavigationController: UINavigationController
                  {
                      var mode: NavigationMode = .Swipe {
                          didSet {
                              self.setButtonAttributes()
                          }
                      }
                  
                      private var leftBarButton: UIBarButtonItem!
                      private var middleBarButton: UIBarButtonItem!
                      private var rightBarButton: UIBarButtonItem!
                      private var rightBarButton2: UIBarButtonItem!
                  
                      override func viewDidLoad()
                      {
                          super.viewDidLoad()
                      }
                  
                      func configureNavigationItem(navigationItem: UINavigationItem)
                      {
                          //Configure the bar buttons text and actions
                  
                  
                          if (self.leftBarButton == nil) {
                              self.leftBarButton = UIBarButtonItem(title: "Menu1", style: .Plain,target: self, action: "menu1Pressed:")
                          }
                          if (self.middleBarButton == nil) {
                              self.middleBarButton = UIBarButtonItem(title: "Games", style: .Plain, target: self, action: "gamesPressed:")
                          }
                          if (self.rightBarButton == nil) {
                              self.rightBarButton = UIBarButtonItem(title: "Menu3", style: .Plain, target: self, action: "menu3Pressed:")
                          }
                          if (self.rightBarButton2 == nil) {
                              self.rightBarButton2 = UIBarButtonItem(title: "Settings", style: .Plain, target: self, action: "settingsPressed:")
                          }
                  
                          self.setButtonAttributes()
                  
                          navigationItem.leftBarButtonItems = [self.leftBarButton, self.middleBarButton, self.rightBarButton, self.rightBarButton2]
                  
                      }
                  

                  更新:

                    let button = UIButton(type: .System)
                          button.setImage(UIImage(named: "play"), forState: .Normal)
                          button.setTitle("Play", forState: .Normal)
                          button.sizeToFit()
                  
                          leftBarButton = UIBarButtonItem(customView: button)
                  
                          if (self.leftBarButton == nil) {
                              self.leftBarButton = UIBarButtonItem(title: "Play", style: .Plain,target: self, action: "Pressed:")
                          }
                  

                  推荐答案

                  您可以创建 UIButton 实例,为其设置图片和标题,然后使用它创建您的 UIBarButtonItem:

                  You can create UIButton instance, set an image and a title for it, and then create your UIBarButtonItem with it:

                      let button = UIButton(type: .System)
                      button.setImage(UIImage(named: "YourImage"), forState: .Normal)
                      button.setTitle("YourTitle", forState: .Normal)
                      button.sizeToFit()
                      self.leftBarButton = UIBarButtonItem(customView: button)
                  

                  添加动作:

                      button.addTarget(self, action: #selector(self.someAction), forControlEvents: .TouchUpInside)
                  

                  self.someAction 在哪里

                  where self.someAction is

                  func someAction() {
                  
                  }
                  

                  这篇关于为栏按钮项目设置图像和标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何动态调整导航栏中标题的大小 下一篇:使用 segues 在 NavigationController 中嵌入 UIViewController

                  相关文章

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

                        <bdo id='VUcyt'></bdo><ul id='VUcyt'></ul>
                      <tfoot id='VUcyt'></tfoot>

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