Incorrect installation on UIToolbar using custom image buttons is incorrect

I have a UIToolbar that I configured with my own background image. Therefore, the appearance of the UIBarButtonItem does not work for me, so I use images that are already ready to show in the panel. I create a custom button element using this method:

+ (UIBarButtonItem *)customWithImage:(UIImage *)image enabled:(BOOL)enabled target:(id)target action:(SEL)selector {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    //I've tried different values for the frame here, but no luck
button.frame = CGRectMake(0, 0, 44, 44);
button.enabled = enabled;
button.showsTouchWhenHighlighted = YES;
[button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
[button setImage:image forState:UIControlStateNormal];

UIBarButtonItem *it = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
    //Tried changing this, to no avail
it.width = 32.f;
return it;

I have one button on the left and one on the right, and I'm trying to make sure that if you click on the far left or right right corner of the UIToolbar, the corresponding button will be pressed. However, with these custom buttons, the targets do not extend completely to the edges of the UIToolbar, but are inserted from the sides:

http://skitch.com/andpoul/d1p8g/hit-targets

Any help is much appreciated!

+3
2

UIBarButtonItem.width , (, ).

, ( ) . .

UIImageView UIButton.

+1

, , , - ( , ) ...

0

Source: https://habr.com/ru/post/1760172/


All Articles