您的位置:首页 > 其它

button点击效果变化与addSubview到哪里有关系

2014-12-14 14:10 162 查看
今天在做项目的过程中,发现,button 的点击效果的决定是由是否添加的是不是self.view上有关。

btn_body = [UIButton
buttonWithType:UIButtonTypeSystem];

btn_body.frame =
CGRectMake(45,
102, 230,
153);
[btn_body
setBackgroundImage:[UIImage
imageNamed:@"body_b1"]
forState:UIControlStateNormal];
[img_portrait
addSubview:btn_body];

这样,btn_body被点击的时候,将不会显示出被点击的效果。
如果是

btn_body = [UIButton
buttonWithType:UIButtonTypeSystem];

btn_body.frame =
CGRectMake(45,
102, 230,
153);
[btn_body
setBackgroundImage:[UIImage
imageNamed:@"body_b1"]
forState:UIControlStateNormal];
[self.view addSubview:btn_body];
这样,btn_body被点击的时候,会显示出被点击的效果。

目前与其他的暂时无关,比如

UIButtonType,isenable,userinterface等等其他属性。之前也 在项目开发的过程中碰到了,用xib拖的button一直是可以出现被点击的时候显示出点击效果的,因为拖到xib中的button是addsubview到self.view上面的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: