I have a button with labels over it. The labels are blocking the button so I cannot click it.
timerView = [[UIView alloc] initWithFrame:CGRectMake(0, 278, 105, 27)];
[self.view addSubview:timerView];
UIButton *timerBackground = [UIButton buttonWithType:UIButtonTypeCustom];
[timerBackground setBackgroundImage:[UIImage imageNamed:@"Time Background.png"] forState:UIControlStateNormal];
[timerBackground setBackgroundImage:[UIImage imageNamed:@"Time Background.png"] forState:UIControlStateHighlighted];
[timerBackground addTarget:self action:@selector(openTimeChanger) forControlEvents:UIControlEventTouchUpInside];
timerBackground.frame = CGRectMake(-2 , 15, 102, 27);
[timerView addSubview:timerBackground];
DateDay = [[UILabel alloc] initWithFrame:CGRectMake(6, 4, 20, 21)];
DateDay.backgroundColor = [UIColor clearColor];
DateDay.textColor = [UIColor whiteColor];
[timerBackground addSubview:DateDay];
I want the label to be ‘transparent’ to clicks, so I can click the button.
UILabel does not block touches, but your view hierarchy does. I’ve added some colors to debug this:
As you see, your button is extending its parent, so everything outside green bounds is inactive, actually, if you click in the very top of black rectangle, where button and parent overlap under the label—you will get a tap event.
To fix this simply align your views so that they’re inside each other.