IOS TableView Split Line height customization

Source: Internet
Author: User

1. The system comes with the form of centralized dividing line mytableview.separatorstyle=uitableviewcellseparatorstylenone; (This is to remove all split lines) can be set by this

2. Also set the custom cell first by Mytableview.separatorstyle=uitableviewcellseparatorstylenone this method to remove all cells, Then in the overloaded cell DrawRect method, through the quartz 2D technology directly to draw, the idea is as follows, first draw the entire cell background color, and then draw the dividing line at the bottom of the cell, below this can set the split line style width and height of the code snippet as follows:

Self-painted split line (seemingly in the iOS7 does not work, on the IOS7 can use the following method) the following method to draw the split line is still not perfect (more than one section of the time below will be a more, do not know how to solve)
-(void) DrawRect: (cgrect) rect
{
Cgcontextref context = Uigraphicsgetcurrentcontext ();

Cgcontextsetfillcolorwithcolor (context, [Uicolor Whitecolor]. Cgcolor);
Cgcontextfillrect (context, rect);

Cgcontextsetstrokecolorwithcolor (context, [Uicolor colorwithred:0xe2/255.0f green:0xe2/255.0f blue:0xE2/255.0f Alpha:1]. Cgcolor);
Cgcontextstrokerect (context, CGRectMake (0, Rect.size.height-1, rect.size.width, 1));
}

In addition, if the iOS7 only want to change the width of the split line position, etc. can be set because this setting only in iOS7 and above can

if ([[[[Uidevice Currentdevice] systemversion] Floatvalue] >= 7) {
Cell.separatorinset = Uiedgeinsetsmake (0, 50, 0, 0);//upper left and right can be set by setting these four parameters to set the split line
}

3. Sometimes it is necessary to remove the extra dividing line to achieve this method through the method of-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: ( Nsindexpath *) Indexpath This method is implemented as follows://Remove the extra cell divider line
if (tableview.datasource>0) {
Tableview.separatorstyle=uitableviewcellseparatorstylesingleline;
[Self setextracelllinehidden:tableview];
}else{
Tableview.separatorstyle=uitableviewcellseparatorstylenone;
}

After this judgment, call the following method to achieve the data when there is no data when there is no split line

-(void) Setextracelllinehidden: (UITableView *) TableView

{
UIView *view =[[UIView alloc]init];
View.backgroundcolor = [Uicolor Clearcolor];
[TableView Settablefooterview:view];
[View release];
}

IOS TableView Split Line height customization

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.