1. <legend id='B6J8Z'><style id='B6J8Z'><dir id='B6J8Z'><q id='B6J8Z'></q></dir></style></legend>

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

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

        如何在 Swift 中为多个按钮使用一个 IBAction?

        时间:2023-07-08
        1. <i id='0fXje'><tr id='0fXje'><dt id='0fXje'><q id='0fXje'><span id='0fXje'><b id='0fXje'><form id='0fXje'><ins id='0fXje'></ins><ul id='0fXje'></ul><sub id='0fXje'></sub></form><legend id='0fXje'></legend><bdo id='0fXje'><pre id='0fXje'><center id='0fXje'></center></pre></bdo></b><th id='0fXje'></th></span></q></dt></tr></i><div id='0fXje'><tfoot id='0fXje'></tfoot><dl id='0fXje'><fieldset id='0fXje'></fieldset></dl></div>
        2. <tfoot id='0fXje'></tfoot>
            <tbody id='0fXje'></tbody>
            <bdo id='0fXje'></bdo><ul id='0fXje'></ul>

              <small id='0fXje'></small><noframes id='0fXje'>

              <legend id='0fXje'><style id='0fXje'><dir id='0fXje'><q id='0fXje'></q></dir></style></legend>

                • 本文介绍了如何在 Swift 中为多个按钮使用一个 IBAction?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有多个按钮,每个按钮都可以切换应用程序的语言.不必为每个按钮创建多个 IBAction,有没有办法将它们全部连接到一个 IBAction 并根据按下的按钮更改语言?我认为在这种情况下使用 switch 语句会很好,但不确定如何设置它.

                  I have multiple buttons each one with the ability to switch the language of the app. Instead of having to create multiple IBActions for each button is there a way to have them all connected to one IBAction and change the language based on the button pressed? I'm thinking a switch statement would be good to use in this situation but not exactly sure how to set it up.

                  推荐答案

                  在 Interface Builder 中,选择 Attributes Inspector 并为每个按钮设置一个唯一编号的 Tag,然后你可以这样做:

                  In Interface Builder, select the Attributes Inspector and set the Tag for each button with a unique number, then you can do something like this:

                  @IBAction changeLanguage(sender: AnyObject) {
                      guard let button = sender as? UIButton else {
                          return
                      }
                  
                      switch button.tag {
                      case 1:
                          // Change to English
                      case 2:
                          // Change to Spanish
                      case 3:
                          // Change to French, etc
                      default:
                          print("Unknown language")
                          return
                      }
                  }
                  

                  要将动作连接到多个按钮:在 Interface Builder 中,右键单击视图层次结构中的 ViewController,然后单击左键将动作连接拖动到每个按钮.

                  To connect the action to multiple buttons: in Interface Builder, right-click ViewController in the view hierarchy, then left-click to drag the action connection to each button.

                  这篇关于如何在 Swift 中为多个按钮使用一个 IBAction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Xcode 8 UIButtons 约束未显示 下一篇:如何增加 UIButton 的选择区域?

                  相关文章

                    • <bdo id='GyShL'></bdo><ul id='GyShL'></ul>

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

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

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