ios - 如何在 UINavigationBar 上设置图像

标签 ios objective-c uinavigationcontroller

设置navigationController一个尺寸为750 × 90图像尺寸的图像

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsDefault];

将图像设置到导航 Controller 后,它在 UINavigationController 上未完全绘制图像。

如何在 UINavigationController 栏上设置图像。

最佳答案

试试这个

use the method of resizableImageWithCapInsets:resizingMode: and set the resizingMode to UIImageResizingModeStretch, else the image would still Same in the navigation bar.

UIImage *currentImgae =  [[UIImage imageNamed:@"bg.png"]
                                     resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch];

[self.navigationController.navigationBar setBackgroundImage:currentImgae forBarMetrics:UIBarMetricsDefault];

swift

let currentImgae = UIImage(named: "bg.png")!.resizableImageWithCapInsets(UIEdgeInsetsMake(0, 0, 0, 0), resizingMode: .Stretch)
self.navigationController.navigationBar.setBackgroundImage(currentImgae!, forBarMetrics: .Default)

关于ios - 如何在 UINavigationBar 上设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39098389/

相关文章:

ios - 在 App Delegate 之外的 ViewController 中注册解析远程通知

ios - 更改 UISearchController 的 UINavigationBar 背景色

ios - 找不到添加 UIBarButtonItem 的位置

ios - 移除导航堆栈中的 ViewController

ios - 源文件中的 Swift 编辑器占位符

ios - 如何通过 FireBase 更新使用推送通知

ios - 滑动以删除 TableView 行

ios - webview 在 objective-c 中不起作用

objective-c - 将 id 转换为指向 NSError 指针的指针 (NSError **)

c++ - 使用 C++ Api 的 Objective C 实现