自定义UIView中的UIButton无法显示

论坛 期权论坛 脚本     
匿名技术用户   2020-12-29 18:32   471   0

以下代码运行时无法显示Button:

- (id)initWithFrame:(CGRect)frame {

self = [superinitWithFrame:frame];

if (self) {

//初始化属性

[selfinitProperty];

//创建组件

[selfcreateComponent];

}

return self;

}


- (void)initProperty

{

self.backgroundColor =UIColorFromRGB_hex(0xffffff);

}


- (void)createComponent

{

_btnConfirm = [UIButtonbuttonWithType:UIButtonTypeCustom];

[_btnConfirmsetTitle:@"OK"forState:UIControlStateNormal];

[_btnConfirmsetBackgroundColor:UIColorFromRGB_hex(0xff00ff)];

[_btnConfirmaddTarget:selfaction:@selector(btnConfirmClicked)forControlEvents:UIControlEventTouchUpInside];

[selfaddSubview:_btnConfirm];

}


- (void)viewDidLoad {

[_btnConfirmsetFrame:CGRectMake(10,self.bounds.origin.y +100, self.bounds.size.width -20, 40)];

}


- (void)viewDidLoad {

[_btnConfirmsetFrame:CGRectMake(10,self.bounds.origin.y +100, self.bounds.size.width -20, 40)];

}


改为

- (void)layoutSubviews {

[_btnConfirmsetFrame:CGRectMake(10,self.bounds.origin.y +100, self.bounds.size.width -20, 40)];

}

即可。viewDidLoad中什么都不需要做。



分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP