我正在尝试更改所有应用的导航栏按钮的背景图像。我想它必须在appDelegate中完成。
非常感谢
答案 0 :(得分:3)
您可以使用外观代理。只需在appDelegate中添加它
即可- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
UIImage *myImage = [UIImage imageNamed:@"barButtonItemBackground.png"];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setBackgroundImage:myImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
return YES;
}
有关更多详细信息,请查看WWDC 2011的会话114
答案 1 :(得分:1)
如果您的目标是iOS 5,则可以将此代码放入AppDelegate:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 5.0)
{
// iPhone 5.0 code here
UIImage *image = [UIImage imageNamed: @"image.png"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}