Customization of UINavigationBar and the back button

后端 未结 4 542
花落未央
花落未央 2020-12-02 09:11

I followed the tutorial below to customize the UINavigationBar.

http://foobarpig.com/iphone/uinavigationbar-with-solid-color-or-image-background.html

I appli

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 09:21

    Here is what you do.

    1) Add custom buttons to your navigation item in the Interface Builder:

    enter image description here

    2) In the code do the following:

    #define IS_IOS7  ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
    
    - (void)viewDidLayoutSubviews {
    
        [super viewDidLayoutSubviews];
    
        if (IS_IOS7) { 
    
            [self shiftView:self.navigationItem.leftBarButtonItem.customView horizontallyBy:-11];
            [self shiftView:self.navigationItem.rightBarButtonItem.customView horizontallyBy:11];
        }
    }
    
    - (void)shiftView:(UIView*)view horizontallyBy:(int)offset {
          CGRect frame = view.frame;
          frame.origin.y += offset;
          view.frame = frame;
    }
    

提交回复
热议问题