简体   繁体   English

UITabbar ios的背景图像

[英]Background image of UITabbar ios

I want to set a custom image as background image of a UITabbar. 我想将自定义图像设置为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. 我知道应用程序中应该有不同大小的可用于支持视网膜和非视网膜,分别为640x98和320x49,并且还为视网膜图像名称添加了@ 2x前缀。

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. 我的问题是图像适合Iphone 4s,5和5s上的标签内的精细,但它不适合Iphone 6,6加,6s,6s plus等。

I guess it has to do with that there are wider screens on the Iphone 6 series. 我想这与Iphone 6系列上有更宽的屏幕有关。 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). 当我增加图像的宽度时,它确实适合Iphone 6系列,但不适用于4s,5和5s(只能看到2/3的图像)。

Senario 塞纳里奥

When I try to run on 4s, 5, and 5s with a image of size 320x49 it fits fine. 当我尝试使用尺寸为320x49的图像在4s,5和5s上运行时,它很合适。 When I run with 640x98 the image is too wide. 当我使用640x98运行时,图像太宽。

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). 当我尝试在6系列上运行320x49时,图像的宽度不足以填满整个标签栏,因此它会被平铺(看起来很奇怪)。 When I run on the 6 series with 640x98 it's fits well. 当我使用640x98运行6系列时,它非常适合。

However I can't seem to combine those two settings, or what am I missing? 但是我似乎无法将这两种设置结合起来,或者我错过了什么?

Thanks, Muff. 谢谢,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). 当你在其中创建一个新的集合时,它将显示不同大小的选项(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. 有通用,iPhone,iPad,Apple TV,Apple手表和Mac。 and when u call the image it'll set accordingly. 当你调用图像时,它会相应地设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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