开发者

Custom Button on top of another custom button?

I'm trying to make two custom buttons in code. One that fills the full screen with a small button on top. The problem I'm having is the larger button is triggered when the smaller button is tapped. I've tried doing exactly the same thing with IB and it works. Is there some sort of trapping/masking method that I need to use with code? I've checked the documentation and not come across anything that would suggest why this is happening.

CGRect bFrame = CGRectMake(0, 0, 320, 480);
UIButton *cancelButton = [[UIButton alloc] init];
cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
cancelButton.frame = bFrame;
[cancelButton setBackgroundColor:[UI开发者_如何学编程Color clearColor]];
[cancelButton addTarget:self action:@selector(animate:) forControlEvents:UIControlEventTouchUpInside];      


UIButton *priceButton = [[UIButton alloc] init];
priceButton.center = CGPointMake(228, 98);
[priceButton addTarget:self action:@selector(callNumber:) forControlEvents:UIControlEventTouchUpInside];
[priceButton setTitle:@"BUY" forState:UIControlStateNormal];

[self.view addSubview:priceButton];
//[cancelButton addSubview:priceButton];
[self.view addSubview:cancelButton];
[self.view bringSubviewToFront:priceButton];


Did you forget to quote the [self.view addSubview:priceButton]; or is that simply missing in your code?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜