How to pass a string as a tag of UIButton

前端 未结 8 1235
刺人心
刺人心 2020-12-16 02:41

The tag value is an Integer:

UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:addressField forState:UIControlStateNormal];
[bu         


        
8条回答
  •  忘掉有多难
    2020-12-16 03:12

    Probably not best practice, but one simple way to pass a string with UIButton is to store it in the accessibilityIdentifier property.

    yourButton.accessibilityIdentifier = "Some string you want to pass"
    

    ...

    @objc func tappedButton(sender: UIButton) {
      print("passed string is: \(sender.accessibilityIdentifier)")
    }
    

提交回复
热议问题