2010-04-06 221 views
0

我想在代码中创建两个自定义按钮。一个用顶部的小按钮填满整个屏幕。我遇到的问题是点击较小的按钮时会触发更大的按钮。我试过用IB来做同样的事情,它的工作原理。是否需要使用代码的某种陷印/遮罩方法?我检查了文档,并没有发现任何可以说明这种情况发生的原因。另一个自定义按钮上的自定义按钮?

CGRect bFrame = CGRectMake(0, 0, 320, 480); 
UIButton *cancelButton = [[UIButton alloc] init]; 
cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
cancelButton.frame = bFrame; 
[cancelButton setBackgroundColor:[UIColor 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]; 

回答

0

您忘记引用[self.view addSubview:priceButton];还是仅仅是代码中缺少的?

+0

糟糕,它滑掉了我的粘贴。我在我原来的代码中。我修改了上面的代码。 – Jim 2010-04-06 23:56:55

+0

有道理,只是想确认一下。我应该把上面的内容写成评论,而不是回答,因为我现在没有进一步的线索了,为什么你会得到这些结果 - 我的不好。 – Till 2010-04-07 00:05:31

+0

感谢您的输入。很高兴知道这不是一件明显的事情(除了我的贴)。 – Jim 2010-04-07 00:31:20