1

I'm creating custom UIView that contains two UILabels and UIButton so I created a subclass to make this possible.

Now the process looks like:

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    self.backgroundColor = [UIColor whiteColor];

    self.settingsButton = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width - 2 * margin, frame.size.height - titleHeight - dateHeight, buttonSize, buttonSize)];
    [self.settingsButton setImage:[UIImage imageNamed:@"settings_icon"] forState:UIControlStateNormal];
    [self addSubview:self.settingsButton];

    [self.settingsButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
    return self;
}

Button appears on UIView but it is not clickable. I tried to set self.userInteractionEnabled = YES; and a couple things but still no result :(

7
  • Check with developer.apple.com/library/content/documentation/… if there isn't an view blocking the touch? Commented Nov 21, 2017 at 17:33
  • This looks okay. How does the rest look? Commented Nov 21, 2017 at 17:35
  • Make sure the button is not outside the UIView's bounds. Easy test: set clipsToBounds=YES and see if the button is still visible Commented Nov 21, 2017 at 17:37
  • @Larme @Wasserfloh this test and debugger's test shows that button is inside UIView's bounds so I have no idea now Commented Nov 21, 2017 at 17:47
  • In response to @Larme 's comment , Press View Hierarchy Debug button on your debug console and see if there is any other view on top of button Commented Nov 21, 2017 at 19:51

1 Answer 1

2

This is the most dumb mistake I've ever made. Transparent UINavigationBar was blocking the touch.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.