UINavigationBar背景图像仅在iOS 7.1中应用两次

时间:2014-03-27 09:50:33

标签: ios ipad uinavigationbar background-image ios7.1

我使用Xcode 5.1在iOS 7.1上测试我的应用程序。我可以看到UINavigationBar背景图像仅在iOS 7.1中应用了两次非视网膜iPad设备。如果我在iPad视网膜设备上运行该应用程序,它会正确显示图像。以下是非视网膜设备

中的屏幕截图

enter image description here

以下是 RETINA设备

的屏幕截图

enter image description here

导航栏背景图片透明。这是我的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];

        [self configUI];

        [self.window makeKeyAndVisible];
        return YES;
    }

    -(void)configUI
    {
        if (IS_IPAD)
            self.homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController~iPad" bundle:nil];
        else
            self.homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController~iPhone" bundle:nil];

        self.navController = [[UINavigationController alloc] initWithRootViewController:self.homeVC];

        UIImage *bg;

        if(IS_IPAD)
            bg = [UIImage imageNamed:@"portrait_screen_bg~ipad"];
        else
            bg = [UIImage imageNamed:IS_IPHONE_5?@"screen_bg_i5":@"screen_bg"];

        UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bg];
        [self.navController.view insertSubview:bgImageView atIndex:0];
        [self.navController.navigationBar setBackgroundColor:[UIColor clearColor]];
        [self.navController.view setBackgroundColor:[UIColor clearColor]];

        if(IS_IPAD)
        {
            // Nav bar image with height = 44
            [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_portrait_ios6~ipad.png"] forBarMetrics:UIBarMetricsDefault];
            [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_landscape_ios6~ipad.png"] forBarMetrics:UIBarMetricsLandscapePhone];

        }
        else
        {
            [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigation_bar_bg"] forBarMetrics:UIBarMetricsDefault];
        }

        UIFont *titleFont = [UIFont fontWithName:@"Avenir-Book" size:20];
        NSDictionary *attrib = [NSDictionary dictionaryWithObjectsAndKeys:
                                titleFont,              NSFontAttributeName,
                                [UIColor whiteColor],   NSForegroundColorAttributeName,
                                nil];

        [[UINavigationBar appearance] setTitleTextAttributes:attrib];
        self.window.rootViewController = self.navController;
    }

我和设计师核对过,图片中没有问题。视网膜和非视网膜图像都是相同的,除了尺寸加倍。

non-retina image size = 768 x 44
retina image size  = 1536 x 88

IMP注意:使用上面的代码,应用效果非常好&在iOS<非视网膜设备中显示正确的图像7.1此问题仅适用于iOS 7.1

0 个答案:

没有答案