ios - 导航 Controller 背景图像使用 xcode 9 在 ios 11 中 self 重复

标签 ios objective-c xcode uinavigationbar xcode9

我曾尝试使用以下代码来设置 UINavigationBar 的背景图片。 它在 Xcode 9 之前工作正常,但在 Xcode 9 中图像设置不正确。

UIImage *image = [UIImage imageNamed:@"headr_bg"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

Xcode 9 image 1

Xcode 9 image 2

[before Xcode 9]

最佳答案

可能不是完美的解决方案& 但是我有一个旧项目,因为我已经通过下面的代码修复了它。刚刚为 iOS 版本 > 11 更新了导航栏位置和导航 View 框架。

CGRect navbarFrame = self.navigationController.navigationBar.frame;
CGRect navFrame = self.navigationController.view.frame;
navbarFrame.size.height = 44;
navFrame.origin.y = 20;
self.navigationController.navigationBar.frame = navbarFrame;
self.navigationController.view.frame = navFrame;

关于ios - 导航 Controller 背景图像使用 xcode 9 在 ios 11 中 self 重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46557827/

相关文章:

objective-c - 如何使用 NSString 检测字符串是否在字符串中

ios - 访问 tableView 单元格内文本字段的 textfield.text

objective-c - iOS 上的电话号码格式

swift - 如何正确编写约束代码

swift - AVSpeechSynthesiser 窃听 ViewDidLoad 功能

ios - 迅速 ,"Type of expression is ambiguous without more context"?

ios - 呀!我们没有遗漏任何 dSYM

ios - NSObject 类中未调用 UIAlertView

ios - 如何在 Xcode 上管理登录和注销过程

iOS 自动布局 : Issues with 2 variable sized boxes and 1 fixed sized box