2013-07-06 49 views
1

有没有一种方法可以为ipad风景/人像模式使用不同的图像?我的导航栏在中间包含一个徽标,虽然它在iPhone上使用不同图像效果很好,但我无法为iPad使用不同的图像,因此在打开设备时徽标未居中。Ipad NavigationBar Landscape问题

另外,我可以使用一个普通的背景图像,也许用图像或中心按钮替换导航栏标题,但我也无法做到这一点。 (我没有UINavigationController子类)。

这里是我的代码,做的伎俩到目前为止应用程序的委托里面:

if ([UINavigationBar respondsToSelector:@selector(appearance)]) { 

     // Create resizable images for iphone 
     UIImage *navbarImage44 = [[UIImage imageNamed:@"nav_bar"] 
            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 

     UIImage *navbarImage32 = [[UIImage imageNamed:@"nav_bar_landscape"] 
            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 

     // Overide for iPad 
     // In theory navbar_bg_landscape~iPad should work 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
      //use iPad specific image extending last pixel for landscape mode 
      [[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:@"nav_bar_ipad" ] 
           resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)] 
               forBarMetrics:UIBarMetricsDefault]; 

     }else { 

      // Set the background image for *all* UINavigationBars 
      [[UINavigationBar appearance] setBackgroundImage:navbarImage44 
               forBarMetrics:UIBarMetricsDefault]; 

      // Never called on iPad, used for landscape on iPhone 
      [[UINavigationBar appearance] setBackgroundImage:navbarImage32 
               forBarMetrics:UIBarMetricsLandscapePhone]; 
     } 



    } 

回答

1

我没有得到这个任何回应,所以我发现周围的工作是调整大小景观的图像。我现在好了。我调整我的肖像的背景图片 - 这是我为iPad

代码
// Create resizable images 
       UIImage *ipadTabBarBG = [[UIImage imageNamed:@"nav_bar_ipad.png"] 
              resizableImageWithCapInsets:UIEdgeInsetsMake(0, -260, 0, 0)]; 

// Set the background image for *all* UINavigationBars 
      [[UINavigationBar appearance] setBackgroundImage:ipadTabBarBG 
               forBarMetrics:UIBarMetricsDefault];