我在app delegate.m中使用此代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
// Rename "specialNavBar.png" to the file name of your specific navigation bar background image.
UIImage *special = [UIImage imageNamed:@"movBar.png"];
// Rename "SpecialViewController" to the class name that you want to have a different navigation bar for.
[[UINavigationBar appearanceWhenContainedIn:[MovableViewController class], nil] setBackgroundImage:special
forBarMetrics:UIBarMetricsDefault];
// Override point for customization after application launch.
return YES;
}
APP正在崩溃并给我这个错误消息:
因未捕获的异常“
NSUnknownKeyException
”而终止应用,原因:'[<MovableViewController 0xa17eb90> setValue:forUndefinedKey:]
:此类不符合键值编码关键navBar
。' * 第一次抛出调用堆栈: (0x1d11012 0x11f3e7e 0x1d99fb1 0xc9fe41 0xc215f8 0xc210e7 0xc4bb58 0x355019 0x1207663 0x1d0c45a 0x353b1c 0x2187e7 0x218dc8 0x218ff8 0x219232 0x1683d5 0x16876f 0x168905 0x171917 0x13596c 0x13694b 0x147cb5 0x148beb 0x13a698 0x1f4adf9 0x1f4aad0 0x1c86bf5 0x1c86962 0x1cb7bb6 0x1cb6f44 0x1cb6e1b 0x13617a 0x137ffc 0x276d 0x2695) libc ++ abi.dylib:terminate调用抛出异常
答案 0 :(得分:3)
您可以在导航栏中添加自定义图像。
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIImage *special = [UIImage imageNamed:@"movBar.png"];
[_window.rootViewController.navigationController.navigationBar setBackgroundImage:special forBarMetrics:UIBarMetricsDefault];
答案 1 :(得分:0)
在视图控制器中要更改其背景的-setBackgroundImage:
上调用UINavigationBar
。然后,在-viewWillDisappear:
方法中,将其设置回原始图像。