简体   繁体   English

iOS标签栏图标模糊

[英]iOS tab bar icons are blurry

My tab bar icons appear blurry. 我的标签栏图标显得模糊。

在此输入图像描述

I created the icons using Photoshop, and followed the iOS Human Interface Guidelines when I decided the sizes of each icons. 我使用Photoshop创建了图标,并在确定每个图标的大小时遵循iOS人机界面指南。

eg icon size: 30x30px png 例如图标大小:30x30px png

This only happens with the tab bar. 这只发生在标签栏上。 I wonder if this happens because of the resolution of the images or because of programming issues... 我想知道是否因为图像的分辨率或编程问题而发生这种情况......

You're using icon size 30x30 which I assume is for 1x ( iPhone<4 ). 您使用的图标大小为30x30 ,我假设是1xiPhone <4 )。 Since iPhone>=4 needs 2x and 3x images so you have to include that also. 由于iPhone> = 4需要2x3x图像,因此您还必须包含它们。

Either you use images with naming conventions like 您可以使用具有命名约定的图像

star.png     // 1x = 30x30
star@2x.png  // 2x = 60x60
star@3x.png  // 3x = 90x90

or you can use image.xcassets and put your 1x , 2x and 3x images there and use it. 或者您可以使用image.xcassets并将1x2x3x图像放在那里并使用它。

Reference Xcode Assets Catalogs 参考Xcode资产目录

Probably because using a device with the retina screen. 可能是因为使用带有视网膜屏幕的设备。

Try about changing the icon's filename to xxx@2x.xxx like "facebook_icon@2x.png". 尝试将图标的文件名更改为xxx@2x.xxx,如“facebook_icon@2x.png”。

Also, be aware that you can use a PDF file (vector graphics, resolution independent) instead of PNGs, and Xcode will render the appropriate resolutions at build time for you (I don't think you can easily do this for third party icons such as Facebook, but...). 此外,请注意您可以使用PDF文件 (矢量图形,独立于分辨率)而不是PNG,Xcode将在构建时为您呈现适当的分辨率(我认为您不能轻易地为第三方图标执行此操作作为Facebook,但......)。

To see how this is done, create a new project using the "Tabbed Application" template, and check the asset catalog for the tab bar icon images. 要查看如何完成此操作,请使用“选项卡式应用程序”模板创建一个新项目,并检查资产目录中的选项卡栏图标图像。 It does just that for the circle and square icons of the "First" and "Second" initial tabs. 它只对“First”和“Second”初始选项卡的圆形和方形图标执行此操作。

使用此行代码在uitabbar中为uitabbaritem设置图像。

tabbaritem.image = [[UIImage imageNamed:@“image”] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

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

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