IOS Some settings for TableView cell split line

Source: Internet
Author: User

For iOS TableView cell division lines, we rarely use the system default, but some projects require us to change the color or shape of the dividing line to match the hue of the whole project. The Apple company has been thinking of us for a long time.

First, about the position of the dividing line.

The position of the dividing line refers to the split line relative to the Tableviewcell. If we want to adjust the position according to the requirements, then after the iOS7.0 version, a method is provided as follows:

if ([Self.tableview respondstoselector: @selector (setseparatorinset:)]) {                [Self.tableview setseparatorinset: Uiedgeinsetsmake (000);            }

Uiedgeinsets four parameters are relative to the cell's top, left, bottom and right distance, are the cgfloat type.

Second, the color and style of the dividing line:

A, the cell's split line color is not the cell's property, it belongs to the TableView Separatorcolor property. So we just need to set the property value to get all the dividing lines of the color we want,

[Self.tableview Setseparatorcolor:[uicolor Clearcolor];

B, cell style: It is TableView's Separatorstyle property, the system provides us with three styles defined in enumeration Uitableviewcellseparatorstyle, respectively

typedef ns_enum (Nsinteger, Uitableviewcellseparatorstyle) {    Uitableviewcellseparatorstylenone,    Uitableviewcellseparatorstylesingleline,    uitableviewcellseparatorstylesinglelineetched   // This separator style was only supported for grouped style table views currently};

The default is Uitableviewcellseparatorstylesingleline.

Three, Tableviewcell split line custom: First to take the cell from the Division line to remove, using the following two kinds of lines, one is to set the color to Clearcolor, the other is the style set to Uitableviewcellseparatorstylenone.

Two ways to customize cell split lines

A, the custom split line as a view on the cell Contentview, it is important to pay attention to the reuse problem, so this view should be added when the cell is initialized. The sample code is as follows:

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{UITableViewCell*cell =Nil; Cell= [TableView dequeuereusablecellwithidentifier:@"Cell"]; if(Cell = =Nil) {Cell= [[UITableViewCell alloc]initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:@"Cell"]; Cell.accessoryview= [[Uiimageview alloc]initwithimage:[uiimage imagenamed:@"Huicellacce"]]; Cell.backgroundcolor=[Uicolor Clearcolor];//cell.selected = YES;Uiimageview *imageviewsepe = [[Uiimageview alloc]initwithframe:cgrectmake ( -, the, $,1)]; Imageviewsepe.image= [UIImage imagenamed:@"Godline"];    [Cell.contentview Addsubview:imageviewsepe]; }
}

b, more complex, the use of the underlying framework,

-(void=
Cgcontextsetstrokecolorwithcolor (context, [uicolorcolorwithhexstring:@ "FFFFFF"]. Cgcolor);
Cgcontextstrokerect (Context, CGRectMake (5,-11//  Cgcontextsetstrokecolorwithcolor (context, [Uicolor colorwithhexstring:@ "e2e2e2"] . Cgcolor); Cgcontextstrokerect (Context, CGRectMake (51)); }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.