【问题标题】:UINavigation Back Button origin in iOS 7iOS 7 中的 UINavigation Back Button 起源
【发布时间】:2014-03-20 09:11:13
【问题描述】:

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

iOS 6 外观:

iOS 7 外观:

如何在iOS 7 中设置UINavigation Back Button origin 与iOS 6 相同?

【问题讨论】:

标签: ios iphone objective-c uinavigationbar uinavigationitem


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    试试这个:

    #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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 2013-09-25
      • 1970-01-01
      • 2013-01-02
      • 2022-12-26
      相关资源
      最近更新 更多