今天在做项目的过程中,发现,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上面的。