The accepted answer does not work for me on iOS 11 and iPhone X (simulator) when I install resizableImageWithCapInsets:UIEdgeInsetsZero . The other answer stretchableImage... seems to work, but does not provide a complete solution. So, I would like to share what I have, after several tests with the API:
First, consider the source code:
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"Tab BG"]]; [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Nav BG"] forBarMetrics:UIBarMetricsDefault];
I found that this works on iPhone 7 and iPhone 7 plus if-and-only - if the PNG files @ 2x and @ 3x correspond to the exact width of these two resolutions, i.e. 750 pixels (375pt) and 1242 pixels (414 pt). Since iPhone SE uses @ 2x PNG with 640 pixels (320 pixels), the right side of the image is cropped. On iPhone X, the height is no longer the same as that of another iPhone, resulting in an image with vertical tiles.
In my situation, it is best to stretch my background both horizontally and vertically (stretch to a suitable one). So my solution creates a stretchable image without covers:
[[UITabBar appearance] setBackgroundImage:[[UIImage imageNamed:@"Tab BG"] stretchableImageWithLeftCapWidth:0 topCapHeight:0]]; [[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:@"Nav BG"] stretchableImageWithLeftCapWidth:0 topCapHeight:0] forBarMetrics:UIBarMetricsDefault];
I tested it on an iPhone X simulator.
source share