iOS 7中的UINavigation Back Button原点

时间:2014-03-20 09:11:14

标签: ios iphone objective-c uinavigationbar uinavigationitem

我创建了自定义UINavigation Back Button。但是iOS 6和iOS 7中按钮的来源是不同的。

iOS 6外观:

enter image description here

iOS 7外观:

enter image description here

如何将iOS 7中的UINavigation Back Button原点设置为与iOS 6中相同?

2 个答案:

答案 0 :(得分:5)

使用此代码修复左栏按钮位置:

    //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];
    }

答案 1 :(得分:0)

试试这个:

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

- (void)setupNavigationButton {
     UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height)];
    //Align button left with view
    if (SYSTEM_VERSION_LESS_THAN(@"7")) {
        backButtonView.bounds = CGRectOffset(backButtonView.bounds, -8, -5);
    } else {
        backButtonView.bounds = CGRectOffset(backButtonView.bounds, 2.5, 0);
    }
    [backButtonView addSubview:button];

    UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
    self.navigationController.navigationItem.leftBarButtonItem = customBarItem;
}
相关问题