rightBarButtonItem frame

Discussion in 'iOS Programming' started by Nnavick, Jun 11, 2012.

  1. Nnavick, Jun 11, 2012
    Last edited: Jun 12, 2012

    Nnavick macrumors regular

    Joined:
    Oct 13, 2010
    #1
    Hi,
    I'm using this code I wrote to create unbutton and assign it to rightBarButtonItem:

    PHP:
      UIButton *rightButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
        
    UIImagerightImage1 = [[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(popUpBlackMenuforControlEvents:UIControlEventTouchUpInside];
        
    rightButton2.frame CGRectMake(005948);
        
    UIBarButtonItem *plusButton2 = [[[UIBarButtonItem allocinitWithCustomView:rightButton2autorelease];
        
    uperBar.rightBarButtonItem plusButton2;

    what happens is that on the right side of the rightBarButtonItem there is space
    [​IMG]

    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, -45948);
      [
    naccontroller.view addSubview:rightButton2];
    But I don't think this is the ideal solution.



    Thanks!
     
  2. Ides macrumors member

    Joined:
    Mar 27, 2012
    #2
    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).
     
  3. Nnavick thread starter macrumors regular

    Joined:
    Oct 13, 2010
    #3
    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
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    I think they just add it as a subview rather then use the standard button things ;) Just my opinion
     
  5. Nnavick thread starter macrumors regular

    Joined:
    Oct 13, 2010
    #5
    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?
     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    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
     

Share This Page