xcode 如何在 XCodes 的 Interface Builder 中定义颜色?

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

How to define colors in XCodes' Interface Builder?

iosxcodecolorsinterface-builder

提问by favo

I would like to copy colors between elements in the Interface Builder or define them using RGB values. For example, I'd like to copy the background color of a button to another button without duplicating the button.

我想在 Interface Builder 中的元素之间复制颜色或使用 RGB 值定义它们。例如,我想将一个按钮的背景颜色复制到另一个按钮而不复制该按钮。

Alternatively, entering exact RGB codes in Interface Builder would suffice; that way I can make sure my buttons have the exact same color.

或者,在 Interface Builder 中输入准确的 RGB 代码就足够了;这样我就可以确保我的按钮具有完全相同的颜色。

Currently I only know how to do this programmatically, but surely there is a way to do it in Interface Builder?

目前我只知道如何以编程方式执行此操作,但是在 Interface Builder 中肯定有办法做到这一点吗?

采纳答案by Vladimir

To set RGB value in IB you should

要在 IB 中设置 RGB 值,您应该

  1. Click on corresponding element in Inspector window to invoke "Colors" dialog (e.g. Background color, text color etc)
  2. On the toolbar choose the "Sliders" icon
  3. Choose "RGB Sliders" in combo box.
  1. 在 Inspector 窗口中单击相应的元素以调用“颜色”对话框(例如背景颜色、文本颜色等)
  2. 在工具栏上选择“滑块”图标
  3. 在组合框中选择“RGB 滑块”。

Now you should be able to set RGB values for the color.

现在您应该能够为颜色设置 RGB 值。

Sorry, I don't know if it is possible to copy color values between different elements easily...

抱歉,我不知道是否可以轻松地在不同元素之间复制颜色值...

回答by M.Y.

To copy a custom-defined color between different elements you should save it. To do this, first define the color in the Colors window (e.g. by entering RGB values into field as described in Vladimir's answer). Then simply drag from the top panel of the colors window where your resulting color is shown into one of the small square boxes at the bottom. It will be saved.

要在不同元素之间复制自定义颜色,您应该保存它。为此,首先在“颜色”窗口中定义颜色(例如,通过在 Vladimir 的回答中描述的字段中输入 RGB 值)。然后简单地从颜色窗口的顶部面板拖动到底部的小方框之一中,在那里您的结果颜色显示。它将被保存。

Illustration

插图

回答by kazi.munshimun

I know it is late answer but it is possible create custom profile in Interface Builder.

我知道这是迟到的答案,但可以在 Interface Builder 中创建自定义配置文件。

First you need to Click on Color of any component in Utilities panel.

首先,您需要在“实用工具”面板中单击任何组件的颜色。

Click on any Color

单击任何颜色

Then select 3rd tab from the top panel and Click on Settings icon on the right.

然后从顶部面板中选择第三个选项卡,然后单击右侧的设置图标。

Select third tab and click settings button

选择第三个选项卡并单击设置按钮

Then select the New option

然后选择新建选项

Select New option

选择新建选项

After creating you can then rename the profile

创建后,您可以重命名配置文件

Rename the color profile

重命名颜色配置文件

Then click on the color picker and select a color from your color pallet

然后单击颜色选择器并从您的调色板中选择一种颜色

Click on color picker

点击颜色选择器

Lastly drag the picked image to upper window to save that color. You can also change the name of picked color.

最后将选取的图像拖到上方的窗口以保存该颜色。您还可以更改选取颜色的名称。

Drag the image to the upper window

将图像拖动到上方窗口

And by repeating this you can add all your color needed for your project in this color pallet. Next you need to change color of component such as Button, Label you just need to select this color profile and select color. Hope it is helpful.

通过重复此操作,您可以在此调色板中添加项目所需的所有颜色。接下来您需要更改按钮、标签等组件的颜色,您只需要选择此颜色配置文件并选择颜色即可。希望它有帮助。

回答by Zack Morris

If you want to match RGB values between Photoshop and Xcode exactly(without conversion between colorspaces) then you need to save your images in generic RGB and enter any dropper values using the generic RGB colorspace.

如果您想在 Photoshop 和 Xcode 之间精确匹配 RGB 值(无需在颜色空间之间进行转换),那么您需要将图像保存为通用 RGB 并使用通用 RGB 颜色空间输入任何滴管值。

  • When you choose "Save for Web & Devices" from Photoshop, uncheck the "Convert to sRGB" box.
  • 当您从 Photoshop 中选择“保存为 Web 和设备”时,请取消选中“转换为 sRGB”框。

enter image description here

在此处输入图片说明

  • In Xcode, click the colorspace popup in the color picker and choose "Generic RGB", then enter the red, green and blue values from Photoshop, NOT THE HEX VALUEas this reverts back to the sRGB colorspace for some reason (be careful not to tab to the hex field either, as that also changes the colorspace to sRGB).
  • 在 Xcode 中,单击颜色选择器中的颜色空间弹出窗口并选择“通用 RGB”,然后从 Photoshop 中输入红色、绿色和蓝色值,而不是十六进制值,因为由于某种原因,这会恢复为 sRGB 颜色空间(注意不要选项卡到十六进制字段,因为这也会将色彩空间更改为 sRGB)。

enter image description here

在此处输入图片说明

More info here, including how to match screenshots.

更多信息在这里,包括如何搭配截图。