开发者社区> 问答> 正文

UIButton自定义属性

我要给UIButton自定义一个属性,我这样做的

MyUIButton.h

@interface MyUIButton : UIButton{

NSString *idx;

}
@property (nonatomic,retain) NSString *idx;
@end
MyUIButton.m

@implementation MyUIButton
@synthesize idx;
@end

import "MyUIButton.h"

MyUIButton *btn = ((MyUIButton *)[MyUIButton buttonWithType:UIButtonTypeRoundedRect]);
btn.idx = @"abcd";

然后报错了:

-[UIRoundedRectButton setIdx:]: unrecognized selector sent to instance 0x816b2a0
难道这样扩展属性不对么?

展开
收起
a123456678 2016-07-19 16:21:54 2021 0
1 条回答
写回答
取消 提交回答
  • -(id)buttonWithType:(UIButtonType)type
    {
      [super buttonWithType:type]; 
       self.idx = @"abcd";
    }
    2019-07-17 19:58:31
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载