ios - 在 Storyboard 中设置 UITabBarItem 图像但在运行应用程序后看起来不同

标签 ios uitabbaritem

1) 我在 Assets.xcassets 中添加了四个 png 图像。 selected image

normal image

2) 在 Storyboard中,我嵌入了一个标签栏 Controller 。设置 TabBarItem 图像。 storyboard setting

3) 但是在运行应用程序之后。我发现图像看起来与我的设置有点不同,我不知道为什么,谁能知道为什么以及如何修复?等你帮忙,谢谢 enter image description here

最佳答案

图像看起来不同的原因是因为它填充了平面颜色,而您的 .png 包含一些白色而不是空白背景。 UIImage 有一个名为 renderingMode 的属性。此属性可以是 defaultAlwaysOriginAlwaysTemplate

因此,对于 UITabBarItem,默认渲染模式是 AlwaysTemplate,这就是填充图像的原因。并且由于您的图像在搜索图标内包含白色背景(它应该不包含绘图)它也会被填充。

所以你有两个选择:
1.去除图标的白色背景。
2. 由于您使用的是 XCAssets,因此您可以在 XCAssets 属性面板中更改渲染模式。

这里是您可以从 XCAssets 执行此操作的地方:

enter image description here

关于ios - 在 Storyboard 中设置 UITabBarItem 图像但在运行应用程序后看起来不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34713453/

相关文章:

ios - 设置新的 UITabBar 框架时,UITabBarItems 消失

iphone - 如何使用Apple自定义UITabBarItem图像?

ios - 无法执行方法--错误 :Value of type 'UITableViewCell' has no member 'getCell'

ios - 如何使用 KVC 访问器来访问可变数组 Objective-C

IOS GoogleDrive API - 通过 1 次执行获取子文件夹中的所有文件

选中后iOS刷新标签栏项目

uitabbarcontroller - 禁用一个 UITabbar 项目的旋转

ios - 无法单击选项卡栏 Controller 中的更多选项列表

ios - 如何使用 Swift 在饼图中正确设置 xValuePosition 和 yValuePosition?

ios - 类型剪贴板在 swift 中没有成员 'objects'