0

我试图继承一些 UIButtons 以获取类似于 button.tag 属性的属性。在这个属性中,我想设置一个 MCPeerID。该属性必须类似于:

button.thePeerID = an MCPeerID
if (button.thePeerID == a peer id)...

不幸的是,标签属性只会保存数字。我知道我必须添加一个 UIButton 类型的新文件并像这样调用它:

SubclassButton *myButton=[SubclassButton buttonWithType:UIButtonTypeRoundedRect];

但是我如何获得所需的属性?

4

1 回答 1

3

您将在头文件 (subclassButton.h) 中设置该属性

@interface SubclassButton : UIButton 

@property (nonatomic, strong) NSString *thePeerId;

@end

…然后您可以按照上面的建议访问它:

myButton.thePeerId = @"abcd";

(当然,类型取决于 McPeerID 实际上是什么。相应地调整)

于 2013-11-08T23:00:07.997 回答