0

有没有办法根据方向更改导航栏的背景图像?我尝试在应用程序委托中使用方法,例如:

-(void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame

{

 UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if(orientation == (UIInterfaceOrientationMaskPortrait)||orientation==(UIInterfaceOrientationMaskPortraitUpsideDown)){

    UIImage *myImage = [UIImage imageNamed:@"borderP.png"];
    UIImage * imageBottom = [UIImage imageNamed:@"bottomP.png"];
    [[UIToolbar appearance] setBackgroundImage:imageBottom forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:myImage forBarMetrics:UIBarMetricsDefault];
    [[UIToolbar appearance] setBackgroundImage:imageBottom forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    NSLog(@"******P******");
}

else if(orientation == (UIInterfaceOrientationMaskLandscapeLeft||orientation== UIInterfaceOrientationMaskLandscapeRight)){


    UIImage *myImage = [UIImage imageNamed:@"borderL.png"];
    UIImage * imageBottom = [UIImage imageNamed:@"borderL.png"];
    [[UIToolbar appearance] setBackgroundImage:imageBottom forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:myImage forBarMetrics:UIBarMetricsDefault];
    [[UIToolbar appearance] setBackgroundImage:imageBottom forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    NSLog(@"******L********");
}

}  

但背景图像不会改变。

有什么建议吗?

4

1 回答 1

0

外观代理仅适用于新实例。要修改已经存在的实例,您需要setBackgroundImage:forToolbarPosition:barMetrics:直接调用它。

于 2013-07-30T19:45:41.000 回答