Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigation Back Button origin in iOS 7

I have created custom UINavigation Back Button. But the origin of the button is different in iOS 6 and iOS 7.

iOS 6 look:

enter image description here

iOS 7 look:

enter image description here

How to set UINavigation Back Button origin in iOS 7 to be the same like in iOS 6?

like image 302
Serghei Pogor Avatar asked Mar 20 '14 09:03

Serghei Pogor


1 Answers

Use this code to fix left bar button position:

    //First add the following macro:
    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

    //Then customize your navigation bar:
    - (void) initNavigationBar
    {
        UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
        {
            negativeSpacer.width = -10;
        }
        else
        {
            negativeSpacer.width = 0;
        }

        UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:_customBackButton];
        self.navigationItem.leftBarButtonItems = @[negativeSpacer,backButton];
    }
like image 144
iOS Dev Avatar answered Nov 16 '22 03:11

iOS Dev