Based on the HIG the size of the button that is tappable should be 44×44. Now I have the following:
UIButton * stop = [UIButton buttonWithType:UIButtonTypeCustom];
[stop setSize:CGSizeMake(15, 18)];
[stop setBackgroundImage:[UIImage imageNamed:@"stop-gray.png"] forState:UIControlStateNormal];
[stop addTarget:self action:@selector(stopPage:) forControlEvents:UIControlEventTouchUpInside];
stopButton_ = [[UIBarButtonItem alloc] initWithCustomView:stop];
The UIBarButtonItem will be put inside a UIToolbar for the iphone. As you notice the size of the image there is smaller than 15, 18. Is there a way to make the tappable area for the UIBarButtonItem as 44×44? Or do I have to create a new icon which has an empty space so that the size is 44×44, what is the best practice for this in the iOS world?
Why are you using a custom view? If you just want a custom image on the button, use
-[UIBarButtonItem initWithImage:style:target:action:]and you’ll get the correct tappable area and standard system behaviors.If there’s something you actually need the custom view for, you shouldn’t need to change your image to leave empty space… just set the
contentHorizontalAlignmentandcontentVerticalAlignmentso that the image is centered instead of filling the view, then size your view however you want.