What is the UIColor of the default UITableView separator?

前端 未结 12 1594
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 15:09

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

It looks like a light gray color, but it\'s not [UIColor lightGrayC

相关标签:
12条回答
  • 2021-01-31 15:26

    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 separatorColor property.

    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 CGColor directly for drawing.

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

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

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


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

    UITableView().separ‌​atorColor
    

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

    let defaultTableSeparato‌​rColor = UITableView().separa‌​torColor
    
    0 讨论(0)
  • 2021-01-31 15:31

    Guys it's very simple:

    UITableView().separatorColor
    
    0 讨论(0)
  • 2021-01-31 15:35

    In Swift 3.0.1, you can do something like this

    yourView.backgroundColor = UITableView().separ‌​atorColor
    
    0 讨论(0)
  • 2021-01-31 15:37

    It seems it changed for iOS 7:

    Now the colour is 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:

    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];
    
    0 讨论(0)
  • 2021-01-31 15:40

    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.

    0 讨论(0)
  • 2021-01-31 15:42
    UITableView * tempTable = [[UITableView alloc] init];
    
    [table setSeparatorColor:tempTable.separatorColor];
    [table setSeparatorStyle:tempTable.separatorStyle];
    table.backgroundView = tempTable.backgroundView;
    
    0 讨论(0)
提交回复
热议问题