I'm a little stuck on this one, I have a UIButton
inside a UIViewController
, but for some reason the UIButton
is not responding.
_downloadButton = [[DownloadButtonViewController alloc] init];
_downloadButton.issue = _issue;
_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);
[self.view addSubview:_downloadButton.view];
UIButton *tmpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tmpButton.titleLabel.text = @"test";
tmpButton.frame = CGRectMake(_downloadButton.view.frame.origin.x, _downloadButton.view.frame.origin.y - 30, _downloadButton.view.frame.size.width, _downloadButton.view.frame.size.height);
[self.view addSubview:tmpButton];
To see if nothing was overlapping it, I added another UIButton
a little lower, even if I add it on the same position it still works.
The structure of my application is like this
- UIViewController
- UIScrollView
- ThumbCover
- UIImageView
- DownloadButton --> NOT WORKING
- UIButton --> WORKING
- UILabel
- ThumbCover
- UIImageView
- DownloadButton --> NOT WORKING
- UIButton --> WORKING
- UILabel
- ThumbCover
- UIImageView
- DownloadButton --> NOT WORKING
- UIButton --> WORKING
- UILabel
- ThumbCover
- UIImageView
- DownloadButton --> NOT WORKING
- UIButton --> WORKING
- UILabel
The DownloadButton
is just a simple UIButton
, nothing special at all.
If your subview has a frame of size zero, you won't be able to tap the button even if you can see it. Using a view debugger from Xcode will show you if this is the issue. Also, check if the subview has user interaction enabled when adding it.
If you want to check If UIButton is Pressed or not, You should handle TouchDown Handler and change button's state to pressed in touchDown hadnler. You can track ToucUpInside method to Change state of button to Not-pressed again.
You have specified the height of the viewcontroller's view as 27
_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);
If your button's frame is outside the frame of its parent view (viewcontroller's view), the abovesaid frame, it wouldn't respond to your touches
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With