我以编程方式向UI添加了两个按钮,如下所示。
这两个按钮有不同的目标,但不知何故,它们都调用最后添加的按钮操作。
例如,对于下面的代码,两个按钮都调用'btnResendCallAction‘方法。
任何帮助都将不胜感激。
self.btnResendSMS = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnResendSMS setFrame:CGRectMake( edge, btn_y, self_w -edge*2, 150)];
[self.btnResendSMS setTitle:strBtnTitle forState:UIControlStateNormal];
//[self.btnResendSMS setTintColor:[UIColor blueColor]];
[self.btnResendSMS setTitleColor:[UIButton buttonWithType:UIButtonTypeCustom].tintColor forState:UIControlStateNormal];
[self.btnResendSMS addTarget:self action:@selector(btnResendSMSAction) forControlEvents:UIControlEventTouchUpInside];
[self.btnResendSMS setEnabled:NO];
[self.btnResendSMS setAlpha:0.3f];
[self.view addSubview:self.btnResendSMS];
self.btnResendCall = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnResendCall setFrame:CGRectMake( edge, btn_y + 60, self_w -edge*2, 150)];
[self.btnResendCall setTitle:strBtnTitleCall forState:UIControlStateNormal];
//[self.btnResendSMS setTintColor:[UIColor blueColor]];
[self.btnResendCall setTitleColor:[UIButton buttonWithType:UIButtonTypeCustom].tintColor forState:UIControlStateNormal];
[self.btnResendCall addTarget:self action:@selector(btnResendCallAction) forControlEvents:UIControlEventTouchUpInside];
[self.btnResendCall setEnabled:NO];
[self.btnResendCall setAlpha:0.3f];
[self.view addSubview:self.btnResendCall];发布于 2020-03-24 07:25:06
实际上,使用该代码,我希望按钮重叠。但这并不明显,因为它们有清晰的背景,没有边界。因此,您认为您正在轻敲按钮1,但您正在轻敲覆盖它的按钮2的部分。
只给按钮2一个红色的背景颜色,这会更明显。
https://stackoverflow.com/questions/60822818
复制相似问题