UIButton inside UIView is not clickable

I am a bit stuck with this, I have it UIButtoninside UIViewController, but for some reason is UIButtonnot 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 this overlaps anything, I added a little more UIButton, even if I add it in the same position that it still works.

The structure of my application is similar to 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

DownloadButton- It's simple UIButton, nothing special at all.

+5
source share
6 answers

You have specified the viewcontroller's view height 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 the frame of your button is outside the frame of its parent view (viewcontroller view), then the inscription that would be higher will not respond to your touch

+15

- ? (, !) , .

0

, , , ...

_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);

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];
[self.view addSubview:_downloadButton.view];

, ...

:)

0

, , . completeTransition:Bool animateTransition:context, , userinteractionEnabled.

0

_downloadButton = [[DownloadButtonViewController alloc] init];

, , , , DownloadButtonViewController UIButton . , DownloadButtonViewController.h ,

@interface DownloadButtonViewController : UIButton
-2
replace this line.. 

tmpButton.titleLabel.text = @"test";

[tmpButton setTitle: @"test" forState:UIControlStateNormal];
-3

All Articles