【问题标题】:Ipad NavigationBar Landscape IssueIpad NavigationBar 横向问题
【发布时间】:2023-03-03 16:03:02
【问题描述】:

有没有办法为 ipad 横向/纵向模式使用不同的图像?我的导航栏在中间包含一个徽标,虽然它在具有不同图像的 iphone 上效果很好,但我不能为 iPad 使用不同的图像,因此当您转动设备时徽标不会居中。

或者,我可以使用纯背景图像,也可以将导航栏标题替换为图像或将按钮居中,但我也无法做到这一点。 (我没有 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];
        }



    }

【问题讨论】:

    标签: ipad uinavigationcontroller landscape


    【解决方案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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多