objective-c - 如何为特定 View 的导航栏设置自定义背景图片

标签 objective-c xcode uinavigationbar ios6.1

我在应用程序 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;

}

应用程序崩溃并给出以下错误消息:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MovableViewController 0xa17eb90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navBar.' * First throw call stack: (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 called throwing an exception

最佳答案

您可以像这样在导航栏中添加自定义图像。

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIImage *special = [UIImage imageNamed:@"movBar.png"];
[_window.rootViewController.navigationController.navigationBar setBackgroundImage:special forBarMetrics:UIBarMetricsDefault];

关于objective-c - 如何为特定 View 的导航栏设置自定义背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16720879/

相关文章:

ios - 管理从普通 NavigationBar 到透明 NavigationBar 的转换

iphone - 如何在设备重启时在后台运行 ios 应用程序?

iphone - 尝试让网络错误警报显示在 iPhone 应用程序上?

ios - 混合 Objective-C/Swift 框架的模块映射位置和编译器设置

iphone - 如何在Xcode中使用svn合并冲突(文件project.pbxproj)?

iphone - <BTSViewController : 0x865c520> 的开始/结束外观转换调用不平衡

iphone - 如何在 iPhone 上的 uinavigationbar 上创建信息按钮

objective-c - NSString 的 NSMutableDictonary 获取 null 值

ios - 在 Ios 的 UIWebview 中加载或查看 .doc 文件

ios - 如何使 if 语句更改 xcode 中的文本字段?