The following is code that I use to add a UIButton to a layer via -addSublayer
:
CAGradientLayer * tile = [[tile alloc] init];
UIButton *XImageButton = [[UIButton alloc]init];
XImageButton.frame= CGRectMake(kXButtonlocX, kXButtonlocY, kXButtonHeight,kXButtonWidth );
[XImageButton setTitle:@"xbutton" forState:UIControlStateNormal];
[XImageButton addTarget:nil action:@selector(XbuttonTouchEvent)
forControlEvents:UIControlEventTouchUpInside];
[tile addSublayer:XImageButton.layer];
The XImageButton
isn't responding to touch events. How can I fix this so that it does respond?