ios 默认 UITableView 分隔符的 UIColor 是什么?

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

What is the UIColor of the default UITableView separator?

iphoneiosuitableviewuicolor

提问by Alejandra

Can anyone tell me the UIColor name or exact RGBA for the default iPhone UITableView separator?

谁能告诉我默认 iPhone UITableView 分隔符的 UIColor 名称或确切的 RGBA?

It looks like a light gray color, but it's not [UIColor lightGrayColor]; it's lighter than that.

它看起来像浅灰色,但它不是[UIColor lightGrayColor];它比那个轻。

采纳答案by Dude

… in terms of CGContextSetRGBStrokeColorit should be:

......就CGContextSetRGBStrokeColor它而言应该是:

CGContextSetRGBStrokeColor (
   CGContextRef c,
   224.0/255.0,
   224.0/255.0,
   224.0/255.0,
   CGFloat alpha
);

Quite simple and hopefully a solution for your problem.

很简单,希望能解决您的问题。

回答by Eonil

The color is not guaranteed to be a specific color. It can be changed over OS and SDK versions. You can retrieve exact color dynamically by accessing separatorColorproperty.

不保证颜色是特定颜色。它可以在 OS 和 SDK 版本之间进行更改。您可以通过访问separatorColor属性动态检索准确的颜色。

UITableView* TV = [[UITableView alloc] init];
UIColor* C = [TV separatorColor];
CGColorRef CGC = [C CGColor];

Now you can get the each channel values through UIColor's methods. Or use the CGColordirectly for drawing.

现在您可以通过UIColor的方法获取每个通道的值。或者CGColor直接使用进行绘图。

Here's header file comment of the property in UITableView.h.

这是UITableView.h.

@property(nonatomic,retain) UIColor *separatorColor;
// default is the standard separator gray

If you want to avoid instantiation cost of UITableViewfor each time, just get it once and cache it.

如果您想避免UITableView每次的实例化成本,只需获取一次并缓存它。



As @Isurunoted in comment, you can write in Swift like this.

正如@Isuru在评论中指出的那样,您可以像这样用 Swift 编写。

UITableView().separ??atorColor

As @Jordannoted in comment, you also can store the result to avoid further evaluation cost.

正如@Jordan在评论中指出的那样,您还可以存储结果以避免进一步的评估成本。

let defaultTableSeparato??rColor = UITableView().separa??torColor

回答by alexey

It seems it changed for iOS 7:

似乎它在iOS 7 中发生了变化:

Now the colour is RGB(200, 199, 204):

现在颜色是 RGB(200, 199, 204):

[UIColor colorWithRed:200/255.0 green:199/255.0 blue:204/255.0 alpha:1.0];

And don't forget the proper line height is 1 px. The code for creating corresponding UIView:

并且不要忘记正确的行高是 1 px。创建对应UIView的代码:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 1/[[UIScreen mainScreen] scale])];
view.backgroundColor = [UIColor colorWithRed:200/255.0 green:199/255.0 blue:204/255.0 alpha:1.0];

回答by ddiego

[UIColor colorWithRed:224/255.0 green:224/255.0 blue:224/255.0 alpha:1.0];

回答by Luke Stanyer

Swift 3

斯威夫特 3

Just set to nil to revert to default.

只需设置为 nil 即可恢复为默认值。

tableView.separatorColor = nil

回答by amergin

To find out any colours on your iOS device, just run the app in the Simulator then use Apple's DigitalColor Meter (in your utilities folder) and hover over the colour you need info on. Alternatively just do a screen grab from the phone, open that in Preview and use DigitalColor Meter to read the colour values.

要找出您的 iOS 设备上的任何颜色,只需在模拟器中运行该应用程序,然后使用 Apple 的 DigitalColor Meter(在您的实用程序文件夹中)并将鼠标悬停在您需要信息的颜色上。或者,只需从手机中抓取屏幕,在预览中打开它并使用 DigitalColor Meter 读取颜色值。

回答by AndrewPK

R: 224 G: 224 B: 224

R:224 G:224 B:224

I hope that helps!

我希望这有帮助!

回答by Pankaj Gaikar

In Swift 3.0.1, you can do something like this

在 Swift 3.0.1 中,你可以做这样的事情

yourView.backgroundColor = UITableView().separ??atorColor

回答by humbolight

FWIW:

FWIW:

UIColor *defaultSeparatorColor = [UIColor colorWithRed:0.783922f green:0.783922f blue:0.8f alpha:1.0f];

UIColor *defaultSeparatorColor = [UIColor colorWithRed:0.783922f green:0.783922f blue:0.8f alpha:1.0f];

This was found simulating iOS 9.0-- and logging out the floating point values that a UITableView separatorColor has by default. I do not find that this matches any of the values from the other answers, but rather exacts the result of the code in the other answer here where the separatorColor is set via creation of a UITableView *tempTable.

这是在模拟iOS 9.0时发现的——并注销了 UITableView separatorColor 默认具有的浮点值。我没有发现这与其他答案中的任何值相匹配,而是在此处通过创建 UITableView *tempTable 来设置 separatorColor 中的其他答案中的代码的结果。

回答by nefarianblack

Screenshot -> Photoshop -> Pick Color Tool -> RGB(227, 227, 229)

Screenshot -> Photoshop -> Pick Color Tool -> RGB(227, 227, 229)