ios - Interface Builder 错误地调整导航项

标签 ios xcode swift interface-builder

我已经搞乱这个问题有一段时间了,但我不知道是什么导致了这个问题。我有一个嵌入在 UINavigationController 中的 UIViewController,并且在生成的 UIViewController 上有两个 UINavigationItems:

1:左按钮是默认的“完成”按钮,没有图像 - 看起来很好 2:右键是一个带有30x30图像的普通按钮

enter image description here

这些按钮未连接到任何 IBOutlet,并且不会在 Swift 代码中进行更改。然而,当代码被编译并在模拟器上运行时,右侧按钮会被按下屏幕。如果删除图像并添加标准文本,则按钮显示正常。

enter image description here

如有任何建议,我们将不胜感激,谢谢

环境详细信息: MacOSX 10.11.2,Xcode 7.2

最佳答案

这就是我在 Objective-C 中所做的,将按钮设置到特定一侧。

UIImage *image = [UIImage imageNamed:@"Notification.png"];
  UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  [button setBackgroundImage:image forState:UIControlStateNormal];
  [button addTarget:self
                action:@selector(goToNotifiationView:)
      forControlEvents:UIControlEventTouchUpInside];
  button.adjustsImageWhenHighlighted = NO;
  UIBarButtonItem *rightButton =
      [[UIBarButtonItem alloc] initWithCustomView:button];
  self.navigationItem.rightBarButtonItem = rightButton;

关于ios - Interface Builder 错误地调整导航项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34884697/

相关文章:

objective-c - OS X 在后台打开 URL 方案

ios - 从 cocos2d-x 代码调用原生 ObjC 类

iphone - 应用程序在 super dealloc 方法中崩溃

ios - 无法在 Safari 中检查我的调试版本

ios - 需要从支付 key PayPal 获得交易 ID

swift - Quick-Nimble 框架中是否有等效的 XCTFail()?

ios - 快速 ScrollView 最后一项为空

php - 要显示的设备特定内容

objective-c - 核心数据支持的 UITableView 中的非核心数据数据

swift - 从 Array<Dictionary<String,String>> 中提取字符串数组的有效方法