简体   繁体   中英

Background image of UITabbar ios

I want to set a custom image as background image of a UITabbar.

I know that there should be different sizes of them available in the app to support retina and non-retina, 640x98 and 320x49 respectively and also add the @2x prefix to the retina image name.

The image I want to use is not symmetric, ie, the colors change a bit as you look at the image from left to right.

The problem I have is that the image fit the fine inside the tabbar on Iphone 4s, 5 and 5s but it doesn't fit on Iphone 6, 6 plus, 6s, 6s plus etc.

I guess it has to do with that there are wider screens on the Iphone 6 series. When I increase the width of the image it does fit inside the Iphone 6 series but not on 4s, 5 and 5s (only 2/3 of the image can be seen).

Senario

When I try to run on 4s, 5, and 5s with a image of size 320x49 it fits fine. When I run with 640x98 the image is too wide.

When I try to run 320x49 on the 6 series the image is not wide enough to fill the whole tabbar, and hence it's gets tiled (looks weird). When I run on the 6 series with 640x98 it's fits well.

However I can't seem to combine those two settings, or what am I missing?

Thanks, Muff.

简单快捷,只需将标签栏设为插座即可:

tabBar.backgroundImage = UIImage(named: "image")

You can try adding the images with different sizes into the image assets file. When u create a new set in it, it'll show options for different sizes (1x,2x,3x). You can also right click and select the device you are targeting. There are Universal, iPhone, iPad, Apple TV, Apple watch and Mac. and when u call the image it'll set accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM