我有一个带有一些按钮作为子视图的自定义 UIView。我阅读了很多关于我的问题的帖子,但发布的解决方案对我不起作用。
如果我将其中一个按钮的框架设置为 UIView 之外的某个坐标,则该按钮可以工作。当我将其中一个按钮的框架设置为自定义 UIView 和按钮重叠的某个坐标时,按钮仅在它们不重叠的区域响应。
这是我的代码:
我在 viewDidLoad 方法中初始化了自定义 UIView:
[super viewDidLoad];
DDButtonBar *ddButtonBar = _ddButtonBar;
[ddButtonBar showButton1:TRUE];
[ddButtonBar showButton2:TRUE];
[ddButtonBar showButton3:TRUE];
[ddButtonBar showButton4:TRUE];
[ddButtonBar showBackButton:TRUE];
[ddButtonBar showSettingsButton:TRUE];
[ddButtonBar setButtonTitle1:@"1"];
[ddButtonBar setButtonTitle2:@"2"];
[ddButtonBar setButtonTitle3:@"3"];
[ddButtonBar setButtonTitle4:@"4"];
这是我的 UIView 的 init 方法:
- (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
// Standardinitialisierung
_drawButton1 = TRUE;
_drawButton2 = TRUE;
_drawButton3 = TRUE;
_drawButton4 = TRUE;
_drawBackButton = TRUE;
_drawSettingsButton = TRUE;
_buttonTitle1 = @"1";
_buttonTitle2 = @"2";
_buttonTitle3 = @"3";
_buttonTitle4 = @"4";
[self layoutSubviews];
}
return self;
}
我正在画我的按钮
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:_buttonTitle1 forState:UIControlStateNormal];
button1.frame = CGRectMake(rechtsverschiebung, height, buttonWidth, height);
[button1 setBackgroundImage:_buttonBackground forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor colorWithRed:255.0 green:255.0 blue:255 alpha:1.0] forState: UIControlStateNormal];
[button1 setTitleColor:[UIColor colorWithRed:247.0 green:165.0 blue:32 alpha:1.0] forState: UIControlStateHighlighted];
[self addSubview:button1];