1
selectgroup = [UIButton buttonWithType:UIButtonTypeCustom];
selectgroup.frame  = CGRectMake(screenWidth/4-23/2, 158, 23, 23) ;
selectgroup.hidden = NO;
UIImage *selectgroupimg = [UIImage imageNamed:@"groupicon2.png"];
[selectgroup setBackgroundImage:selectgroupimg forState:UIControlStateNormal];
//[selectgroup setcontentEdgeInsets : UIEdgeInsetsMake(0, 150, screenWidht/2, 30)];
[selectgroup addTarget:self action:@selector(selectgroup:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:selectgroup];

I want to increase the clickable area of the button to (0,150,screenwidth/2,30). I have try to set contentEdgeInsets and imageEdgeinsets but both doesn't work.

How can I do that?

Waitak Jong
  • 87
  • 11

2 Answers2

1

You need to set image like (Button property setImage and setBackgroundImage both are different)

UIImage *btnImage = [UIImage imageNamed:@"image.png"];
[buttonObject setImage:btnImage forState:UIControlStateNormal];forState:UIControlStateNormal];

then Set button frame you want

buttonObject.frame  = CGRectMake(0,150,screenwidth/2,30);
Jugal K Balara
  • 917
  • 5
  • 15
0

Subclass UIButton, Or category/extension,, and use it like this:

-(BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    return CGRectContainsPoint(UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(-44, -44, -44, -44)), point);
}
MCMatan
  • 8,623
  • 6
  • 46
  • 85