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];
}
}