Passing multiple tags with UIButton(使用 UIButton 传递多个标签)
问题描述
好的,我有一个具体的情况.我正在使用自定义类来创建一些按钮,我可以使用唯一的数字设置它们的标签属性,例如:
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 传递多个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 UIButton 传递多个标签


- UITextView 内容插图 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- URL编码Swift iOS 2022-01-01