ios UIBarButtonItem 图像应该有多大?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1590170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:33:25  来源:igfitidea点击:

How big should a UIBarButtonItem image be?

iosuikituibarbuttonitemuibaritem

提问by Epsilon Prime

I'm looking to create my own custom Sort By Date and Sort By Number buttons that I plan on placing in the navigation bar as the right button.

我希望创建我自己的自定义“按日期排序”和“按数字排序”按钮,我计划将它们作为右侧按钮放置在导航栏中。

How big should my image be to appropriately fill the space -- the UIBarItemdocumentation page doesn't list anything about the size the image should be.

我的图像应该有多大才能适当地填充空间——UIBarItem文档页面没有列出任何关于图像应该大小的信息。

回答by Sixten Otto

As of iOS 11, the Human Interface Guidelinessuggest glyphs be about 25×25 points in toolbars and navigation bars, up to a maximum of about 28 points. (And the HIG should definitely be in your bookmarks if you're working on iOS apps!)

从 iOS 11 开始,人机界面指南建议工具栏和导航栏中的字形约为 25×25 点,最多约为 28 点。(如果您正在开发 iOS 应用程序,HIG 绝对应该在您的书签中!)

That would translate to images 25px square for older devices like iPad 2 / Mini, 50px square for most current devices like iPhone 8 or iPad, and 75px square for Retina HD devices (the iPhone 6/7/8 Plus, or iPhone X). Asset catalogs will help immensely in keeping the different asset sizes organized (and Xcode can even generate them from vector sourcesthese days).

这将转换为 iPad 2 / Mini 等旧设备的 25 像素正方形图像,iPhone 8 或 iPad 等大多数当前设备的 50 像素正方形图像,以及 Retina 高清设备(iPhone 6/7/8 Plus 或 iPhone X)的 75 像素正方形图像。资产目录将极大地帮助组织不同的资产大小(现在 Xcode 甚至可以从矢量源生成它们)。

回答by hashier

The Human Interface Guidelinestells you this since iOS7:

自 iOS7 以来,人机界面指南告诉您这一点:

Regardless of the icon's visual style, create a toolbar or navigation bar icon in the following sizes:

About 44 x 44 pixels

About 22 x 22 pixels (standard resolution)

无论图标的视觉风格如何,都可以创建以下尺寸的工具栏或导航栏图标:

约 44 x 44 像素

约 22 x 22 像素(标准分辨率)

Here is a great matrixof allneeded sizes for resources for all platforms

这里是一个巨大的矩阵所有需要的尺寸为各平台资源

回答by Peter Tretyakov

Yes, Apple suggest to use images with 22px, 44px and 66px size for UIBarButtonItems, but if you use preinstalled icons like Bookmark icon, it's sized by 25px 50px and 75px for 1x, 2x and 3x respectively.

是的,Apple 建议为 使用 22px、44px 和 66px 大小的图像UIBarButtonItems,但如果您使用预先安装的图标(如书签图标),它的大小分别为 25px、50px 和 75px,分别用于 1x、2x 和 3x。

Here are 2 icons in UIToolbar. On the right is Apple's system bookmark icon and on the left my custom icon.

这里有 2 个图标UIToolbar。右边是苹果的系统书签图标,左边是我的自定义图标。

Here my custom icon sized 22px-44px-66px:

这里我的自定义图标大小为 22px-44px-66px:

enter image description here

在此处输入图片说明

And here 25px-50px-75px:

这里是 25px-50px-75px:

enter image description here

在此处输入图片说明

So, if you use custom and system icons in one toolbar, I would suggest to use 25px-50px-75px scaling, or your custom icons will be smaller. In fact I always use 25px-50px-75px scaling, it looks better on toolbars, as for me.

因此,如果您在一个工具栏中使用自定义图标和系统图标,我建议使用 25px-50px-75px 缩放,否则您的自定义图标会更小。事实上我总是使用 25px-50px-75px 缩放,它在工具栏上看起来更好,对我来说。

回答by jobima

Easy: Include your images in Assets.xcassets.

简单:在 Assets.xcassets 中包含您的图像。

How?

如何?

  • Clic on Assets.xcassets
  • Clic + icon and then click "New Image Set"
  • Drag and drop your image to 3x slot
  • Rename the image set
  • In the BarButton you can use this name under "Image" field
  • 单击 Assets.xcassets
  • 单击 + 图标,然后单击“新建图像集”
  • 将您的图像拖放到 3x 插槽
  • 重命名图像集
  • 在 BarButton 中,您可以在“图像”字段下使用此名称