我正在使用 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/