Reputation: 8957
I have three custom buttons with non-rectangular images close to each other in my view. Then I have a problem with touchable area's of each button overlap with other buttons. So how can I limit the touchable area of each buttons to get the corresponding actions?
Upvotes: 5
Views: 1205
Reputation: 539
You should create custom Type Buttons and add required images on each using this code:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[btn setFrame:frame];
Creating buttons with images this way will not result in overlapping images issues !!
Upvotes: 3
Reputation: 18343
Use two components. A UIImageView
with a smaller UIButton
on top.
Upvotes: 3
Reputation: 52237
You can overwrite -pointInside:withEvent:
, that internally will be used for hit testing.
A nice project using this technique is OBShapedButton, where transparent pixel will not trigger a hit.
Upvotes: 6