ios TabBarItems 并设置它们的图像大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29874499/
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-31 05:46:26  来源:igfitidea点击:

TabBarItems and setting their image sizes?

iosuitabbar

提问by MooCow

I am currently adding images to each one of my tab bar items. One image I like has a size that is much bigger then the area of the bar item. When I set the image of the bar item in the storyboard and run the emulator... the bar button with that image covers the entire screen.

我目前正在为我的每个标签栏项目添加图像。我喜欢的一张图片的尺寸比酒吧项目的面积大得多。当我在故事板中设置条形项目的图像并运行模拟器时......带有该图像的条形按钮覆盖整个屏幕。

Now I thought there was some automatic way of allowing the images to resize for each bar button. This is sadly not the case. Is there a way when the tab bar loads that I can resize the images within each tab bar?

现在我认为有一些自动方法可以让图像为每个条形按钮调整大小。遗憾的是,情况并非如此。有没有办法在标签栏加载时调整每个标签栏中的图像大小?

回答by Leo Dabus

You should prepare 3 images icons for each tab bar item (1x, 2x and 3x).

您应该为每个标签栏项目(1x、2x 和 3x)准备 3 个图像图标。

First create the 3x at 75w 75h pixels (maximum: 144 x 96) and save it as [email protected].

首先在 75w 75h 像素处创建 3x(最大:144 x 96)并将其保存为 [email protected]

Then resize it to 50w 50h pixels (maximum: 96 x 64) and save it as [email protected].

然后将其调整为 50w 50h 像素(最大:96 x 64)并将其保存为 [email protected]

Finally resize it to 25w 25h pixels (maximum: 48 x 32) and save it as iconTab0.png.

最后将其调整为 25w 25h 像素(最大:48 x 32)并将其保存为 iconTab0.png。

Now all you need is to select those 3 images at your finder and drag them to your image assets.

现在您只需要在取景器中选择这 3 张图像并将它们拖到您的图像资产中即可。

Human Interface Guidelines

人机界面指南

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Mark Moeykens

Another option is to create a vector image PDF. What you do is resize your vector image to the smallest size (22x22) and export it to a PDF file. You can do this with Adobe Illustrator, Sketch and many other vector image editing tools.

另一种选择是创建矢量图像 PDF。您要做的是将矢量图像调整为最小尺寸 (22x22) 并将其导出为 PDF 文件。您可以使用 Adob​​e Illustrator、Sketch 和许多其他矢量图像编辑工具来做到这一点。

Then you add the PDF file to your assets folder and in the Properties Inspector set "Scale Factors" to "Single Vector". That should do it!

然后将 PDF 文件添加到资产文件夹,并在属性检查器中将“比例因子”设置为“单一向量”。应该这样做!

回答by Ryan Walton

Pretty easy to do this with ios8. In Storyboard, click on each tab item (the individual controller for the tab you want to change the image of.

很容易做到这一点ios8。在 Storyboard 中,单击每个选项卡项(要更改其图像的选项卡的单个控制器。

Set the insetsaccordingly...

相应地设置insets...

enter image description here

在此处输入图片说明

There is this issuethough. Fixed with this.

不过有这个问题。用这个固定。

回答by Colin Hong

@LeoDabus provided a good answer.

@LeoDabus 提供了一个很好的答案。

For resizing the image, a good and easy way to do this is to:

要调整图像大小,一个很好且简单的方法是:

  1. Add your image to the 1x, 2x, 3x boxes in Assets.xcassets folder.
  2. Then, click on the image in each box and double-finger tap the trackpad/right-click which will reveal the options here:
  1. 将您的图像添加到 Assets.xcassets 文件夹中的 1x、2x、3x 框。
  2. 然后,单击每个框中的图像并双指点击触控板/右键单击,这将显示此处的选项:

Open with External Editor

使用外部编辑器打开

  1. Click on 'Open with External Editor', which will bring you to Preview.
  2. Click on 'Tools' then 'Adjust Size'.
  1. 单击“使用外部编辑器打开”,这将带您进入预览。
  2. 单击“工具”,然后单击“调整大小”。

Adjust Size

调整大小

  1. Adjust the size of your image based on your requirements. Then hit 'Save' and close the window. The image in Xcode should be auto-updated.
  1. 根据您的要求调整图像的大小。然后点击“保存”并关闭窗口。Xcode 中的图像应该自动更新。