Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nnavick

macrumors regular
Original poster
Oct 13, 2010
100
0
Hi,
I'm using this code I wrote to create unbutton and assign it to rightBarButtonItem:

PHP:
  UIButton *rightButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage* rightImage1 = [[UIImage imageNamed:@"DropDownMenu.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];
    [rightButton2 setBackgroundImage:rightImage1 forState:UIControlStateNormal];
    [rightButton2 setBackgroundImage:rightImage1 forState:UIControlStateDisabled];
    rightImage1 = [[UIImage imageNamed:@"DropDownMenuPressed.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];
    [rightButton2 setBackgroundImage:rightImage1 forState:UIControlStateHighlighted];
    [rightButton2 addTarget:self action:@selector(popUpBlackMenu) forControlEvents:UIControlEventTouchUpInside];
    rightButton2.frame = CGRectMake(0, 0, 59, 48);
    UIBarButtonItem *plusButton2 = [[[UIBarButtonItem alloc] initWithCustomView:rightButton2] autorelease];
    uperBar.rightBarButtonItem = plusButton2;


what happens is that on the right side of the rightBarButtonItem there is space
33269455.png


and I don't know what is the problem.
Maybe changing the rightBarButtonItem frame to the UIButton frame will solve the problem?

EDIT:

I added the button as button and not as BarButton.

PHP:
 rightButton2.frame = CGRectMake(261, -4, 59, 48);
  [naccontroller.view addSubview:rightButton2];

But I don't think this is the ideal solution.



Thanks!
 
Last edited:
Space

The UIToolbar class manages it's bar button items well, and you don't need to mess with their frames much. The space that you're seeing is supposed to be there, it makes the interface look cleaner. As far as I know, there's no way to remove that space (correct me if I'm wrong).
 
The UIToolbar class manages it's bar button items well, and you don't need to mess with their frames much. The space that you're seeing is supposed to be there, it makes the interface look cleaner. As far as I know, there's no way to remove that space (correct me if I'm wrong).

I saw couple of apps on the app store(foursquare for example) that removed this space,so it's possible :)
but I don't know how
 
I think they just add it as a subview rather then use the standard button things ;) Just my opinion

That's exactly what I did :D

But when they push a new view in the UINav controller the right button(or the UIButton as subview) is flicking just like a real right button.

Do you think it's an animation they added?
 
That's exactly what I did :D

But when they push a new view in the UINav controller the right button(or the UIButton as subview) is flicking just like a real right button.

Do you think it's an animation they added?

If you go to your own profile and press Stats for example, it flickers a bit, This can be done with

Code:
    [UIView animateWithDuration:0.1 animations:^{
        self.view.alpha = 0.0;
    }completion:^(BOOL finished) {
        [UIView animateWithDuration:0.1 animations:^{
            self.view.alpha = 1.0;
        }];
    }];

you can exchange self.view with the button
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.