问题描述
好的,我有一个具体的情况.我正在使用自定义类来创建一些按钮,我可以使用唯一的数字设置它们的标签属性,例如:
OK I have a specific situation. I am using a custom class to create some buttons and I can set their tag property with unique numbers like:
button.tag =[NSNumber numberWithInt:[10]];
这在我程序的另一部分非常有用,因为我可以访问这个独特的标签,例如:
This is very useful in another part of my program because I can access this unique tag like:
UIButton *clicked= (UIButton *) sender;
ButtonTag = [NSString stringWithFormat:@"%d", clicked.tag];
现在我想再传递一个像这样的独特属性.我正在编造这个,但这就是我的设想
Now I want to pass one more unique property just like this. I am making this up but this is how I envision it
button.tagCREATED_BY_ME =[NSNumber numberWithInt:[9000]];
这个问题可能措辞不好,但我不知道更好,所以我称之为标签".(正确的措辞可能是元素/属性等)我如何创建一个类似的属性来像 .tag 一样发挥作用?
The question might be poorly worded but I don't know any better so I called it "tag".(correct wording might be element/property etc) How do I create a similar property to function just like .tag?
非常感谢!阿尔达
推荐答案
在你的子类/自定义按钮中,你可以添加一个字符串属性,甚至是一个整数属性,只要你觉得好.
In your subclassed/custom button, you can add a string property or even an integer property whichever you feel good.
@interface CustomButton: ....
...
@property(strong) NSString *createdBy;
@end
然后你可以访问那些 aButton.createdBy
Then you can access those as aButton.createdBy
这篇关于使用 UIButton 传递多个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!