【问题标题】:Custom UIBarButtonItem not working properly in iOS8自定义 UIBarButtonItem 在 iOS8 中无法正常工作
【发布时间】:2014-09-25 20:28:11
【问题描述】:

我正在设置一个自定义 UIBarButtonItem,它在 iOS 7 上运行良好,但在 iOS 8 中,我看到分页中的下一个视图控制器的后退图标显示在当前可见页面上。我在 UIScrollView 中有多个视图控制器。

请在下面查看我的代码。如果我尝试删除负间隔,它可以正常工作,但是后退图标会移到右侧并且看起来不太好。

请提供想法。

UIImage *backArrow = [UIImage imageNamed:@"back.png"];
UIButton *aBackButton = [UIButton buttonWithType:UIButtonTypeSystem];
CGSize aBackButtonTextSize = [MyLocalized(BackButtonKey) sizeWithFont:[UIFont systemFontOfSize:kFontSize17]];
aBackButton.frame = CGRectMake(kScreenOrigin, kScreenOrigin, aBackButtonTextSize.width + backArrow.size.width, self.navigationController.navigationBar.frame.size.height);
aBackButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[aBackButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
[aBackButton setTitle:MyLocalized(BackButtonKey) forState:UIControlStateNormal];
[aBackButton setImage:backArrow forState:UIControlStateNormal];
UIBarButtonItem *aLeftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aBackButton];
UIBarButtonItem *aNegativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
aNegativeSpacer.width = -8;
self.navigationItem.leftBarButtonItems = @[aNegativeSpacer, aLeftBarButtonItem];

【问题讨论】:

    标签: ios cocoa-touch uiscrollview uibarbuttonitem


    【解决方案1】:

    嗯... 您可以将另一个“正垫片”作为左第三个按钮来补偿第一个。无论如何,这对我来说似乎太复杂了。如何实现自定义 UIBarButtonItem 的最佳方法是(如我所见)子类 UIBarButtonItem 并“内部”实现其行为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 2017-03-25
      相关资源
      最近更新 更多