Interface Builder错误地调整导航项

时间:2016-01-19 18:49:54

标签: 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

1 个答案:

答案 0 :(得分:0)

这就是我在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;