0

I have a UIBarButtonItem that I want hugging the very left of the screen. I've tried putting a fixed barbutton with width=0 before the button and other configurations but there's always several pixels between the button and x=0.

I've also tried changing the imageInset of the UIButton

UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
moreButton.frame = CGRectMake(0, 0, 60, 35);
[moreButton setImage:[UIImage imageNamed:@"Morebutton"] forState:UIControlStateNormal];
moreButton.imageEdgeInsets = UIEdgeInsetsMake(0, -8, 0, 8);
[moreButton addTarget:self action:@selector(pressedMoreButton:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *moreBar = [[[UIBarButtonItem alloc] initWithCustomView:moreButton] autorelease];

But tapping near the edge of the screen doesn't trigger the selector (probably because only the image is moved but not the button itself) and increasing the size of the button doesn't affect the gap between the button and the left side.

Thanks

technerd
  • 14,144
  • 10
  • 61
  • 92
Andrew Park
  • 1,489
  • 1
  • 17
  • 26

1 Answers1

0

try to put your button to the container view and change position of button on the view.

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];   
    button.contentMode = UIViewContentModeScaleAspectFit;       
    button.frame= CGRectMake(-4.0, 0.0, 30, 30);
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

    UIView *v=[[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, cellTextSize.width+10, buttonImage.size.height)] autorelease];
    v.backgroundColor = [UIColor clearColor];
    [v addSubview:button];

    return [[[UIBarButtonItem alloc] initWithCustomView:v] autorelease];
hypercrypt
  • 15,389
  • 6
  • 48
  • 59
Evgeniy S
  • 1,464
  • 12
  • 32