objective-c - 呈现模态视图 Controller 时更改 UINavigationBar 背景的问题

标签 objective-c ios uinavigationbar

我正在使用 this更改我的 uiviewcontrollers 背景的方法。它通常在我推送 View Controller 时有效。

但是,如果使用

呈现 View Controller
[self presentModalViewController:customViewController animated:YES];

那么,这段代码就不起作用了。任何人都可以提出错误的建议吗?

使用的代码:

要在导航栏中显示图像,您必须自己绘制它,这实际上并不难。将其保存为 UINavigationBar+CustomBackground.m(它向 UINavigationBar 添加自定义类别):

@implementation UINavigationBar (CustomBackground)

- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"NavMain.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}

@end

最佳答案

如果您在 iOS 5 上运行,则不再调用 drawRect:

您将需要使用 UIAppearance 或子类 UINavigationController 并使用它来更改图像。

可以找到UIAppearance 教程here

(drawRect: 仍适用于 iOS 5 以下的版本)

关于objective-c - 呈现模态视图 Controller 时更改 UINavigationBar 背景的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9640721/

相关文章:

objective-c - NSTableView 问题 - 使用 SplitView 面板显示自定义 TableView

ios - 为什么直接将对象分配给属性时 ARC 无法正常工作

ios - 解析 BLE 制造商数据 - Objective-C

c++ - 我可以在 BlackBerry 10 中使用 Xcode 编译的 armv7/armv7s .so 库吗?

ios - UINavigationItem 标题截断

ios - 在 UITableViewCell 中有条件地显示图像

ios - Mapbox iOS8 Swift mapView.showUsersLocation

ios - 检测 UIBezierPath 是否可见

ios - UINavigationBar 后退按钮重复两次

ios - 自定义特定后退按钮的标题属性