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)); }