iOS tableView分割线高度自定义

1.系统自带的集中分割线的形式 myTableView.separatorStyle=UITableViewCellSeparatorStyleNone;(这个是去掉全部分割线)能够经过这个来设置ios

  2.另外设置自定义的cell 首先经过myTableView.separatorStyle=UITableViewCellSeparatorStyleNone这个方法去掉全部的cell,而后在重载cell的drawRect方法,经过Quartz 2D技术直接进行绘制,思路以下,首先绘制整个cell的背景色,而后在cell的最下面绘制分割线,下面这个就能够本身设置分割线的样式 宽度和高度了代码片断以下:it

// 自绘分割线( 貌似在ios7上不起做用,在ios7上能够使用下面的方法)  下面的这个方法绘制的分割线仍是不够完美 (多个section的时候下面会多出一条,不知道怎么解决)
- (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));
}io

另外若是在ios7先只想改变分割线的宽度位置等能够经过设置 由于这个设置只有在ios7及以上才能够table

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
cell.separatorInset = UIEdgeInsetsMake(0, 50, 0, 0);//上左下右 就能够经过设置这四个参数来设置分割线了
}ios7

3.有时候须要去掉多余的分割线 就能够经过一下这个方法实现  这个方法要在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath这个方法中实现 以下://去掉多余的cell 分割线
if (tableView.dataSource>0) {
tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
[self setExtraCellLineHidden:tableView];
}else{
tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
}float

通过这个判断以后调用下面的方法就能够实现 有数据时就有分割线没有数据时就没有分割线方法

 - (void)setExtraCellLineHidden: (UITableView *)tableView技术

   {
UIView *view =[ [UIView alloc]init];
view.backgroundColor = [UIColor clearColor];
[tableView setTableFooterView:view];
[view release];
}数据

相关文章
相关标签/搜索