iOS 关于tableView cell的分割线的一些设置
2016-11-30 10:26
573 查看
对于iOS的tableView的cell的分割线,一般我们很少使用不是系统默认的,但是有些项目要求还是要求我们去改变分割线的颜色或者外形以配合整个项目的色调。这个苹果公司早都为我们想到了。
一、关于分割线的位置。
分割线的位置就是指分割线相对于tableViewCell.如果我们要根据要求调节其位置,那么在iOS7.0版本以后,提供了一个方法如下
//cell俩端都空出10 [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 10, 0,10)]
UIEdgeInsets 的四个参数分别是相对于cell的上、左、下、右的距离,都是CGFloat型。
二、分割线的颜色及风格:
a、cell的分割线的颜色不是cell的属性,它属于tableView的separatorColor属性。这样我们只需要设置属性值就可以得到所有我们想要的颜色的分割线、
[self.tableView setSeparatorColor:[UIColor clearColor]];
b、cell的风格:它是tableView 的separatorStyle属性,系统给我们提供了三种风格在枚举UITableViewCellSeparatorStyle中定义,分别是
typedef NS_ENUM(NSInteger, UITableViewCellSeparatorStyle) { UITableViewCellSeparatorStyleNone, UITableViewCellSeparatorStyleSingleLine, UITableViewCellSeparatorStyleSingleLineEtched // This separator style is only supported for grouped style table views currently };
默认的是UITableViewCellSeparatorStyleSingleLine.
三、tableViewCell 分割线自定义:首先要把cell自带的分割线给去掉,使用如下两种都行,一是把颜色设置为clearColor,二是风格设置为UITableViewCellSeparatorStyleNone。
自定义cell分割线大致用到的两种方法 a、把自定义的分割线当成一个View放到cell的contentView上,一定要注意重用问题,所以这个view 要在cell初始化的时候添加上。示例代码如下:
复制代码
- (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(47, 49, 200, 1)]; imageViewSepE.image = [UIImage imageNamed:@"godline"]; [cell.contentView addSubview:imageViewSepE]; } }
复制代码
b、比较复杂,用到了底层的框架,
复制代码
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect); CGContextSetStrokeColorWithColor(context, [UIColorcolorWithHexString:@"ffffff"].CGColor); CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1)); //下分割线 CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor); }
相关文章推荐
- iOS 关于tableView cell的分割线的一些设置
- iOS 关于tableView cell的分割线的一些设置
- iOS 关于tableView cell的分割线的一些设置
- iOS中tableView cell分割线的一些设置技巧
- 关于TableView Cell的一些设置
- iOS tableView cell的分割线设置
- iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见
- iOS隐藏tableview多余的分割线以及解决cell左边短20px
- ios tableView隐藏多余的cell分割线separator
- iOS tableView 在设置了footView的情况下,系统自带分割线时而消失,时而出现的问题
- ios tableView设置cell选中颜色以及表格默认选中某行
- ios tableView那些事 (十)设置 tableview 的分割线
- 关于tableView group样式 时设置 cell的width 宽度
- iOS开发技巧-tableView去掉多余的空行分割线,自定义Cell分割线
- IOS uitableview中cell的分割线设置距离,并且去掉cell的边框,要不然多了一条细线
- TableView 去掉多余行数、IOS最后一行Cell系统分割线顶头
- 去掉tableview中cell的分割线的设置
- cell设置没有选中效果,tableVIew设置没有分割线
- iOS tableView去掉显示多余的cell分割线
- 关于tableview 的一些属性设置