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

      • <bdo id='Vgf9o'></bdo><ul id='Vgf9o'></ul>
      <legend id='Vgf9o'><style id='Vgf9o'><dir id='Vgf9o'><q id='Vgf9o'></q></dir></style></legend>
      <tfoot id='Vgf9o'></tfoot>

      <i id='Vgf9o'><tr id='Vgf9o'><dt id='Vgf9o'><q id='Vgf9o'><span id='Vgf9o'><b id='Vgf9o'><form id='Vgf9o'><ins id='Vgf9o'></ins><ul id='Vgf9o'></ul><sub id='Vgf9o'></sub></form><legend id='Vgf9o'></legend><bdo id='Vgf9o'><pre id='Vgf9o'><center id='Vgf9o'></center></pre></bdo></b><th id='Vgf9o'></th></span></q></dt></tr></i><div id='Vgf9o'><tfoot id='Vgf9o'></tfoot><dl id='Vgf9o'><fieldset id='Vgf9o'></fieldset></dl></div>
      1. 将字符串属性添加到 Swift 中的 UIButton

        时间:2023-07-30
          <tbody id='oJuAv'></tbody>
          <legend id='oJuAv'><style id='oJuAv'><dir id='oJuAv'><q id='oJuAv'></q></dir></style></legend>

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

              • <bdo id='oJuAv'></bdo><ul id='oJuAv'></ul>
                  <i id='oJuAv'><tr id='oJuAv'><dt id='oJuAv'><q id='oJuAv'><span id='oJuAv'><b id='oJuAv'><form id='oJuAv'><ins id='oJuAv'></ins><ul id='oJuAv'></ul><sub id='oJuAv'></sub></form><legend id='oJuAv'></legend><bdo id='oJuAv'><pre id='oJuAv'><center id='oJuAv'></center></pre></bdo></b><th id='oJuAv'></th></span></q></dt></tr></i><div id='oJuAv'><tfoot id='oJuAv'></tfoot><dl id='oJuAv'><fieldset id='oJuAv'></fieldset></dl></div>
                  <tfoot id='oJuAv'></tfoot>
                  本文介绍了将字符串属性添加到 Swift 中的 UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在 Swift 中将字符串属性与 UIButton 关联?我不希望字符串显示为按钮文本,只是作为标识符或键分配给按钮.这是我到目前为止所拥有的:

                  How can I associate a string property with a UIButton in Swift? I don't want the string to appear as the button text, simply to be assigned to the button as an identifier or a key. Here is what I have so far:

                  func createAnswerButtons() {
                  
                      var index:Int
                      for index = 0; index < self.currentQuestion?.answers.count; index++ {
                  
                          // Create an answer button view
                          var answer:AnswerButtonView = AnswerButtonView()
                          selection.setTranslatesAutoresizingMaskIntoConstraints(false)
                  
                          // Place into content view
                          self.scrollViewContentView.addSubview(answer)
                  
                          // Add a tapped gesture recognizer to the button
                          let tapGesture:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("answerTapped:"))
                          answer.addGestureRecognizer(tapGesture)
                  
                          // Add constraints etc
                  
                          // Set the answer button text
                          let answerText = self.currentQuestion!.answers[index]
                          answer.setAnswerText(answerText)
                  
                          // Set the identifier for each answer button
                          self.identifier = self.currentQuestion!.answerIdentifier[index]
                  
                          // Add to the selection button array
                          self.answerButtonArray.append(answer)
                  }
                  

                  所以我想我之后需要一些东西

                  So I think I need something after

                  // Set the identifier for each answer
                          self.identifier = self.currentQuestion!.answerIdentifier[index]
                  

                  将标识符分配给按钮.

                  这样做的原因是我正在尝试实现决策树逻辑,以便我可以跟踪每个被点击的答案按钮以生成与最终结果相对应的代码字符串.

                  The reason for this is I'm trying to implement a decision tree logic so that I can keep track of each answer button that is tapped to generate a code string that will correspond to a final result.

                  推荐答案

                  如果你想识别的按钮应该有一个唯一的标识符(这个如果您曾经编写 UI 测试,这很重要).

                  You can use the accessibility identifier (button.accessibilityIdentifier), if the button you want to identify should have a unique identifier (this matters if you're ever writing UI tests).

                  您还可以继承 UIButton 并添加一个变量 buttonIdentifier.

                  You can also subclass UIButton and add a variable buttonIdentifier.

                  class IdentifiedButton: UIButton {
                      var buttonIdentifier: String?
                  }
                  

                  这篇关于将字符串属性添加到 Swift 中的 UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UIControlStateHighlighted 和 UIControlStateSelected 有什么区别? 下一篇:如何根据 iphone 中的文本大小动态增加按钮宽度?

                  相关文章

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

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

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

                      <tfoot id='v1Ors'></tfoot>