Question

I've got a UIButton declared in interface builder with an outlet set as follows:

@property (weak, nonatomic) IBOutlet UIButton *loginButton;

It works fine until I insert a subview. Then it stops responding. Here's the offending line:

[self.loginButton insertSubview:_gradientButtonView atIndex:0];

Commenting that out makes the button work again. Here's all the code involved (using the awesome SSToolkit and a custom category on UIColor):

SSGradientView *_gradientButtonView = [[SSGradientView alloc] initWithFrame:self.loginButton.layer.bounds];
_gradientButtonView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_gradientButtonView.topBorderColor = [UIColor colorWithRed:0.558f green:0.599f blue:0.643f alpha:1.0f];
_gradientButtonView.topInsetColor = [UIColor colorWithWhite:1.0f alpha:0.3f];
_gradientButtonView.colors = [NSArray arrayWithObjects:[UIColor from_hex:@"E6E7E8"], [UIColor from_hex:@"A7A9AC"], nil];
_gradientButtonView.layer.cornerRadius = 5;
self.loginButton.layer.cornerRadius = 5;
self.loginButton.titleLabel.shadowOffset = CGSizeMake(0, 1);
[self.loginButton setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.loginButton.layer.masksToBounds = YES;
_gradientView.bottomBorderColor = [UIColor colorWithRed:0.428f green:0.479f blue:0.520f alpha:1.0f];
_gradientButtonView.clipsToBounds = YES;
_gradientButtonView.userInteractionEnabled = YES;
[self.loginButton insertSubview:_gradientButtonView atIndex:0];
self.loginButton.userInteractionEnabled = YES;
Was it helpful?

Solution

This was answered in the comments above:

Is there a specific reason you're writing _gradientButtonView.userInteractionEnabled = YES;? To my knowledge, this prevents the view from sending touch events up the responder chain

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top