我已经搞乱这个问题有一段时间了,但我不知道是什么导致了这个问题。我有一个嵌入在 UINavigationController 中的 UIViewController,并且在生成的 UIViewController 上有两个 UINavigationItems:
1:左按钮是默认的“完成”按钮,没有图像 - 看起来很好 2:右键是一个带有30x30图像的普通按钮
这些按钮未连接到任何 IBOutlet,并且不会在 Swift 代码中进行更改。然而,当代码被编译并在模拟器上运行时,右侧按钮会被按下屏幕。如果删除图像并添加标准文本,则按钮显示正常。
如有任何建议,我们将不胜感激,谢谢
环境详细信息: 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/