I have created a simple UIControl subclass. In its initWithFrame method I create GradientBackgroundView (UIView subclass) and add it as a subview.
Code:
- (id)initWithFrame:(CGRect)frame skinColor:(UIColor*)Color{
if (self = [super initWithFrame:frame]) {
// Initialization code
self.skinColor = Color;
self.backgroundColor = [UIColor clearColor];
GradientBackgroundView* gbView = [[GradientBackgroundView alloc] initWithFrame:CGRectMake(4.0, 4.0, frame.size.width-8.0, frame.size.height-8.0)];
gbView.tintColor = Color;
gbView.userInteractionEnabled = YES;
[self addSubview:gbView];
[gbView release];
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.height)];
label.text = @"Cancel";
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 0;
[self addSubview:label];
[label release];
}
return self;
}
The problem is my target/selector isn't invoked when I tap anywhere within gbView. Tapping within the 4 pixels boundary around it does invoke the target/selector.
It also works when I comment out gbView (leaving only the UILabel as a subview).
It looks like gbView consumes touch events somehow, i.e. blocking them before the UIControl can process them. UILabel obviously doesn't do that.
Is there anything I failed to set in gbView to pass touch events to its superview (UIControl)?