What are the correct dimensions for a custom tab bar item background image?

后端 未结 6 726
北海茫月
北海茫月 2021-01-13 15:11

So I have a .png that\'s 428x176 px:

I want to use it as a tab bar background image for when an item is in the selected state. The problem is t

6条回答
  •  情歌与酒
    2021-01-13 15:40

    Use the below two lines.

    self.tabBarController.tabBar.autoresizesSubviews = NO;
    self.tabBarController.tabBar.clipsToBounds = YES;
    

    Xcode works with point, not pixels, so the width will always be 320. In the case of retina display one point is 2x2 pixels and in normal mode it is 1x1.

    I think the height for the tab bar should be 320x49 for normal and 640x98 for retina.

    the retina image should have the same name as the normal one with the @2x at the end.

    Rename your image to tabbarBack@2x.png. This is called pixel doubling for the Retina Display.

    Without the @2x iOS doesn't know that it should apply a scale factor and it will be used as it is and though it should be halved.

    • tabbarBack.png (45 px or so)

    • tabbarBack@2x.png

      [[[self tabBarController] tabBar] setBackgroundImage:[UIImage imageNamed:@"tabbarBack.png"]];

提交回复
热议问题