Allow UIBarButtonItem to touch the top and bottom of the UINavigationBar

Take a look at the iPhone Droplr app:

enter image description here

Please note that UIBarButtonItem can touch the right, left, top and bottom of the screen / navigation bar?

How can I achieve something like this? This is how I make a UIBarButton sample and set it to the right element:

 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:image forState:UIControlStateNormal]; button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height); [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *bb = [[[UIBarButtonItem alloc] initWithCustomView:button]autorelease]; [self.navigationItem setRightBarButtonItem:bb animated:YES]; 

However, it does not align to the right and has quite a bit of difference above and below. My image size is correct (44px) and it looks like it is compressing it to fit the frame.

So how can I do this?


Edit: Oops, the upper / lower interval was my mistake. However, I cannot figure out how to align the panel button with the left / right side. Here is what I mean: (sorry for the ugly button, it was just a test)

enter image description here

I tried to set the image inserts, but it didn't seem to do anything.

+8
iphone cocoa-touch uinavigationbar uibarbuttonitem
source share
1 answer
 UIView *rightview = [[UIView alloc] initWithFrame:CGRectMake(0,0,30,30)]; UIButton *searchbutton = [[UIButton alloc] initWithFrame:CGRectMake(2,2,50, 30)]; [searchbutton setImage:[UIImage imageNamed:@"some-pic.png"] forState: UIControlStateNormal]; [rightview addSubview:searchbutton]; UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:rightview]; self.navigationItem.rightBarButtonItem = customItem; [customItem release]; 

I am using customView for rightBarButtonItem and I am aligning it correctly. Just try a little with CGRectMake-Numbers for the x-coordinate, for testing I added to the big numbers ...

+11
source share

All Articles