xcode 如何在情节提要中找出对象的 RGB 颜色

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

How can I find out the RGB color of my object in storyboard

iosxcodestoryboarduicolor

提问by Esqarrouth

I have a button in the storyboard, I gave it a color magnesium. I am doing some programming on the button which will change its color on certain situations.

我在故事板中有一个按钮,我给了它一个彩色镁。我正在对按钮进行一些编程,该按钮会在某些情况下改变其颜色。

I like the original color of the button in the storyboard and I want to return back to that color at some event.

我喜欢故事板中按钮的原始颜色,我想在某个事件中恢复到那个颜色。

Now the problem is that color I am using doesn't have a text name (yellowcolor, purplecolor) in UIColor and I can't find the RGB values from the storyboard color picker.

现在的问题是我使用的颜色在 UIColor 中没有文本名称(黄色、紫色),而且我无法从故事板颜色选择器中找到 RGB 值。

Any ideas?

有任何想法吗?

采纳答案by Esqarrouth

Xcode->Select Object->Attributes Inspector->Text Color->Other->Color Sliders->Dropdown Menu->RGB Sliders

Xcode->选择对象->属性检查器->文本颜色->其他->颜色滑块->下拉菜单->RGB滑块

回答by Akshit Zaveri

Follow this screen shot. I am on Windows 8 right now so i just edited the picture but it will certainly give you the way to achieve what you want.

按照这个屏幕截图。我现在在 Windows 8 上,所以我只是编辑了图片,但它肯定会给你实现你想要的方式。

(I combined two DIFFERENT images. So don't freak out. Sorry.)

(我结合了两个不同的图像。所以不要害怕。对不起。)

enter image description here

在此处输入图片说明

回答by Basheer_CAD

You can do this to get the RBG from UIColor:

您可以这样做以从 UIColor 获取 RBG:

CGFloat red = self.btn.backgroundColor.CIColor.red;
    CGFloat blue = self.btn.backgroundColor.CIColor.blue;
    CGFloat green = self.btn.backgroundColor.CIColor.green;
    CGFloat alpha = self.btn.backgroundColor.CIColor.alpha;