iOS UITableViewCell cell Dash Those things Han Junqiang's blog

Source: Internet
Author: User

Daily Update Attention :Http://weibo.com/hanjunqiang

In the development of the cell split line is often encountered or want to customize the width of the line high; Recently summed up, hope to help everyone:

1. What if I don't want to dash?

TableView.separatorSt YLE = Uitableviewcellseparatorstylesingleline;        Sets the system default line style-(void) Viewdidlayoutsubviews {if ([TableView respondstoselector: @selector (setseparatorinset:)]) {    [TableView Setseparatorinset:uiedgeinsetszero]; } if ([TableView respondstoselector: @selector (setlayoutmargins:)]) {[TableView Setlayoutmargins:uiedgeinsetsze    RO]; }}-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: (Nsindexpath *) indexpat{if ([Cell respondstoselector: @selector (setlayoutmargins:)]) {[Cell Setlayoutmargins:uiedgeinsetszer    O];    } if ([Cell respondstoselector: @selector (setseparatorinset:)]) {[Cell Setseparatorinset:uiedgeinsetszero]; }}
Daily update concern :http://weibo.com/hanjunqiang
2. What if I want to set the dash?

 TableView.separatorSt  YLE = Uitableviewcellseparatorstylenone; Drop the line of the system, draw a custom line # define Single_line_height (1/[uiscreen mainscreen].scale)//Line height # define Color_line_gray [Uicolor Colo rwithred:224/255.0f green:224/255.0f blue:224/255.0f alpha:1]//Split Line Color #e0e0e0在自定义cell里写入:-(void) DrawRect: (CGRect)    rect{Cgcontextref context = Uigraphicsgetcurrentcontext (); Cgcontextsetfillcolorwithcolor (context, [Uicolor Clearcolor].    Cgcolor);    Cgcontextfillrect (context, rect); Under Split line Cgcontextsetstrokecolorwithcolor (context, Color_line_gray. Cgcolor); Color_line_gray for Line Color cgcontextstrokerect (context, CGRectMake (0, Rect.size.height, Rect.size.width, single_line_he ight)); Single_line_height is the height of the line} 
Daily Update Attention :Http://weibo.com/hanjunqiang

iOS Developers Exchange QQ Group :446310206 have problems or technical exchanges can be consulted! Welcome to join !




iOS UITableViewCell cell Dash Those things Han Junqiang's blog

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.