How to pass a string as a tag of UIButton

前端 未结 8 1208
刺人心
刺人心 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 02:57

    You can convert the integer value of a tag to a NSString with:

    [NSString stringWithFormat:@"%i", ((UIControl*)sender).tag];
    

    Or, if you really need a string as identifier for an UI object, just subclass it and add a property like:

    @property (nonatomic, strong) NSString *stringID;
    

    And then use it instead of use the tag property.

提交回复
热议问题