Reputation: 13178
I'm using the below code to add a UIButton
to my UIView
:
rejectButton = [UIButton buttonWithType:UIButtonTypeCustom];
[rejectButton addTarget:self action:@selector(rejectBuddy:) forControlEvents:UIControlEventTouchDown];
[rejectButton.titleLabel setFont:[UIFont fontWithName:@"Heiti SC Medium" size:15]];
rejectButton.titleLabel.userInteractionEnabled = NO;
[rejectButton setTitle:@"Reject" forState:UIControlStateNormal];
[rejectButton setBackgroundImage:[UIImage imageNamed:@"Logout_Profile.png"] forState:UIControlStateNormal];
rejectButton.frame = CGRectMake(168, 380, 141.0, 45.0);
rejectButton.userInteractionEnabled = YES;
[mainView addSubview:rejectButton];
When I click the button, it's not doing anything. I'm not even seeing the animation that the button was pressed. Is there anything I am missing with this?
It's working when I manually create a UIButton
on the UIView
on the storyboard. But for my use case, thats not possible.
Upvotes: 0
Views: 508
Reputation: 1735
Got this problem before, and it seems like my animated transitioning is not yet completed. I forgot to to put completeTransition:Bool
at the end of my animateTransition:context
method.
Upvotes: 0
Reputation: 9414
Add the following to enable highlighting on touch. Make sure your UIView has userInteractionEnabled enabled as well. And you may want to use UIControlEventTouchUp.
rejectButton.showsTouchWhenHighlighted = YES;
and comment out
//rejectButton.titleLabel.userInteractionEnabled = NO;
Upvotes: 1