xcode 默认 UIButton 的文本是什么颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15976634/
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
What color is the text of a default UIButton?
提问by zeeple
What color is the text of a default UIButton
? I am trying o recreate it in some table view cells but not having luck. The closest I have come is:
默认文本的颜色是什么UIButton
?我正在尝试在某些表视图单元格中重新创建它,但没有运气。我最接近的是:
[UIColor colorWithRed:0/255.0 green:51.0/255.0 blue:102.0/255.0 alpha:1];
Is that color, font size and style documented anywhere?
该颜色、字体大小和样式是否记录在任何地方?
回答by Stefan Arentz
This is a pretty old question but I thought I would add my own answer anyway.
这是一个很老的问题,但我想无论如何我都会添加我自己的答案。
If you need a custom 'text only' button on iOS 7 and up that has the same color then do not create it with UIButton()
but with UIButton.buttonWithType(UIButtonType.System)
.
如果您在 iOS 7 及更高版本上需要具有相同颜色的自定义“纯文本”按钮,则不要UIButton()
使用UIButton.buttonWithType(UIButtonType.System)
.
That will give you a text button with the same properties as a standard system button, including the correct color. You can then use this button as a template and change things like the font size or add an image, etc.
这将为您提供一个与标准系统按钮具有相同属性的文本按钮,包括正确的颜色。然后,您可以将此按钮用作模板并更改字体大小或添加图像等内容。
回答by virindh
- Run a sample app with a UIButton on the simulator
- Use spotlight to search for 'DigitalColor Meter'(with out the quotes, see below)
- Use the pointer to point it at the text color, this will give you the RGB Value of the text
- The font size and other values can be found using IB.
- 在模拟器上运行带有 UIButton 的示例应用
- 使用聚光灯搜索“DigitalColor Meter”(不带引号,见下文)
- 使用指针将其指向文本颜色,这将为您提供文本的 RGB 值
- 可以使用 IB 找到字体大小和其他值。
回答by Toastor
Try the following:
请尝试以下操作:
CGFloat red;
CGFloat green;
CGFloat blue;
CGFloat alpha;
UILabel *buttonLabel = [yourButton titleLabel];
UIColor *textColor = [buttonLabel textColor];
[textColor getRed:&red green:&green blue:&blue alpha:&alpha];
Now red, green, blue and alpha will contain the values you're looking for:
现在红色、绿色、蓝色和 alpha 将包含您要查找的值:
NSLog(@"Red: %f Green:%f Blue:%f Alpha:%f", red, green, blue, alpha);
For iOS 6 this will return:
对于 iOS 6,这将返回:
Red:0.220000 Green:0.330000 Blue:0.530000 Alpha:1.000000
回答by ChrisBob
Text Color to Match Default UIButton Color [Blue]
It looks like someone pulled it out programmatically, but I have not confirmed it.
好像有人用编程的方式把它拉出来了,但我还没有确认。
回答by Timm Liberty
Personally what I would do is capture the color of the text in viewDidLoad using the property currentTitleColor and then use that when needed. That way you don't have to worry about rgb and the rest.
我个人会做的是使用属性 currentTitleColor 在 viewDidLoad 中捕获文本的颜色,然后在需要时使用它。这样您就不必担心 rgb 和其他问题。
So in the interface set up a UIColor property and Outlet for your button
所以在界面中为你的按钮设置一个 UIColor 属性和 Outlet
@property (strong,nonatomic)UIColor *backToTheDefaultTextColor;
@property (weak, nonatomic) IBOutlet UIButton *myButton;
In viewDidLoad get the buttons title color with
在 viewDidLoad 中获取按钮标题颜色
_backToTheDefaultTextColor = _myButton.currentTitleColor;
Then after you have changed the color of the title of the button and want to revert back simply put
然后在您更改按钮标题的颜色并想恢复后,只需将
_myButton.titleLabel.textColor = _backToTheDefaultColor;