TableViewCell 自定义分割线

cell的分割线长度不用是整个屏幕宽,并且设计要求分割线为2px(两条),上下不同色。

实现如下: 
UITableView中将分割线样式改为None

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;  

自定义UITableViewCell中复写- (void)drawRect:(CGRect)rect方法

- (void)drawRect:(CGRect)rect
{
            CGContextRef context = UIGraphicsGetCurrentContext();  

            CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
            CGContextFillRect(context, rect);  

        //上分割线,
            CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"ffffff"].CGColor);
            CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1));  

        //下分割线
            CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor);
            CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10, 1));  

} 
时间: 2024-08-06 14:15:03

TableViewCell 自定义分割线的相关文章

TableViewCell自定义分割线

产品设计的要求cell的分割线长度不用是整个屏幕宽,并且设计要求分割线为2px(两条),上下不同色. 实现如下: UITableView中将分割线样式改为None [java] view plain copy tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 自定义UITableViewCell中复写- (void)drawRect:(CGRect)rect方法 [java] view plain copy - (void

TableViewCell的分割线左边没有空隙

//TableViewCell的分割线处理 左边没有空隙-(void)viewDidLayoutSubviews {        if ([_tbView respondsToSelector:@selector(setSeparatorInset:)]) {        [_tbView setSeparatorInset:UIEdgeInsetsZero];            }    if ([_tbView respondsToSelector:@selector(setLayo

自定义tableviewCell的分割线

第一种:addsubview UIView *line = [[UIView alloc]initWithFrame:CGRectMake(10, cellH-0.5, DEVW-10, 0.5)]; line.backgroundColor = ViewLineColor; 第二种:自绘分割线. 首先设置tableView的separatorStyle为UITableViewCellSelectionStyleNone,即禁用tableview自带的分割线,然后在重载cell的drawRect

UITableViewCell自定义分割线

产品设计今天要求cell的分割线不能是整个屏幕的长度,这时候我们有两种方法可以解决 方法一就是自己写一个label放在cell上 方法二就是自定义一个分割线,方法如下 首先我们要去掉cell默认的分割线,设为none [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; 然后实现- (void)drawRect:(CGRect)rect方法 - (void)drawRect:(CGRect)rect{ //首先

TableViewCell的分割线显示不完全处理方法

1.加方法,隐藏分割线 - (void)viewDidLoad { [super viewDidLoad]; //设置tableView不能滚动 [self.tableView setScrollEnabled:NO]; //在此处调用一下就可以啦 :此处假设tableView的name叫:tableView [self setExtraCellLineHidden:self.tableView]; } -(void)setExtraCellLineHidden: (UITableView *)

iOS开发笔记--cell最右边显示箭头,字符,自定义分割线

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier]; if (0 == i

tableview左滑按钮 tableviewcell自定义左滑按钮

当我们在使用tableview时,往往需要在cell左滑时显示一个或是多个按钮,但系统默认的只可显示一个,如常见的删除按钮,那么当我们的需求要求要有多个按钮时又该怎么办呢,我们往下看. 首先,现看看系统的按钮(只显示一个按钮时) //设置cell左滑后的删除按钮文字 -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)ind

tableViewCell的分割线短一截的问题

最近在写很简单的tableView的布局时,发现系统自带的Cell分割线短了15像素,不过这个可以更改,纯代码方式如下: //设置分割线到头,不再断15像素 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsZero]; } 在ios7系统运行上面的就可以搞定,不过ios8 必须加上下面的方法和内容,否则依然短15

ListView取消和自定义分割线的方法

一.不显示分割线 XML android:footerDividersEnabled="false"即可. JAVA mListView.setDivider(null); 二.改变分割线颜色和高度 XML android:divider android:dividerHeight JAVA listView.setDivider(drawable);如果想扩大listview每项间的距离,并让分割线消失可以这样设置 mListView.setDividerHeight(10); 三.