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

1、加方法,隐藏分割线

- (void)viewDidLoad

{

[super viewDidLoad];

//设置tableView不能滚动

[self.tableView setScrollEnabled:NO];

//在此处调用一下就可以啦 :此处假设tableView的name叫:tableView

[self setExtraCellLineHidden:self.tableView];

}

-(void)setExtraCellLineHidden: (UITableView *)tableView
{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];

}

2、cell显示内容时候,用图片替换

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

staticNSString *cellID =@"Cell";

_cell = [tableViewdequeueReusableCellWithIdentifier:cellID];

if (_cell ==nil) {

_cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellID];

UIImageView *separatorLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, cell.frame.size.height - 1.0f, cell.frame.size.width,1.0f)];

separatorLine.image = [[UIImage imageNamed:@"grayDot"] stretchableImageWithLeftCapWidth:1 topCapHeight:0];

separatorLine.tag = 4;

[cell.contentView addSubview:separatorLine];

UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];

separatorLine.hidden = NO;

}

UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];

separatorLine.hidden = NO;

3、自定义的cell,在上面画自己画一条线和屏幕宽度一样长

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));

}

4、重写父类的方法

-(void)viewDidLayoutSubviews {
    
    if ([self.mytableview respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.mytableview setSeparatorInset:UIEdgeInsetsZero];

}
    if ([self.mytableview respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.mytableview setLayoutMargins:UIEdgeInsetsZero];
    }

}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

时间: 2024-07-29 01:17:48

TableViewCell的分割线显示不完全处理方法的相关文章

TableViewCell的分割线显示不全解决方法

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsZero]; } if ([cell resp

UIWebView显示本地图片的方法

在UIWebView显示本地图片,由此可借助UIWebView实现图文混排(内容编码成html格式即可). // ViewController.m // // Created by zc on 8/1/14. // Copyright (c) 2014 cuibo. All rights reserved. // #import "ViewController.h" @interface ViewController () <UIWebViewDelegate> @prop

Android SDK无法显示更新列表解决方法

解决办法: 第一步: 打开Windows中C:\WINDOWS\system32\drivers\etc\hosts,然后添加以下内容: 203.208.46.146 dl.google.com 203.208.46.146 dl-ssl.google.com 74.125.113.121 developer.android.com 第二步: 打开Android SDK Manager,选上方的菜单Tools,进入Options,在"Force https://- "前面打钩,就可以更

HighChats图表控件显示精度小数点的方法

相信大家对highchats这个图表控件并不陌生,最近在项目中用到它,但是某些字段需要显示为小数点,顾查找资料文档发现下面两个方式可以实现: 初始化时候添加如下两个参数 tooltip:{??? formatter:function(){??? return''+this.point.name+': '+Math.round(this.percentage)+' %';??? }},plotOptions:{?????? pie:{?????? allowPointSelect:true,???

ubuntu 中用vim打开txt等文件中文显示乱码的解决方法 &nbsp;

今晚用ubuntu 12.04 的vim编辑网页代码时,发现上面的中文显示乱码.这个html文件是我之前用gedit编辑的,在gedit里面显示正常,可是在vim下显示就是乱码了. 怎么解决ubuntu中vim显示中文乱码的问题呢? 首先,添加中文字符编码: sudo gedit /var/lib/locales/supported.d/local 在打开的文件中添加下面的中文字符集 zh_CN.GBK GBK zh_CN.GB2312 GB2312 zh_CN.GB18030 GB18030

Sublime的中文GBK显示乱码的解决方法

import urllib2,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.

cmake管理visual studio无法显示头文件解决方法

原因 我们的跨平台项目使用cmake来管理的,但是windows下的小伙伴发现在visual studio上头文件没有加载进来,于是手工加载,事情过去了.然后,有一天我修改了CMakeLists.txt文件,visual studio居然自动去重新生成了项目,然后头文件就没有了.哭吧---- 解决方法 source_group 可以将文件分目录来显示在IDE中.所以,修改了一下base.cmake文件让所有的项目都能检索出头文件并显示在 include 文件夹中. file(GLOB_RECUR

数据库显示可疑的修复方法

在使用SQL Server 2008数据库时发现数据库被标记为可疑,查看网上的资料终于找到了解决办法,接下来我们就来介绍解决方法. 解决方法: 当数据库发生这种操作故障时,可以按如下操作步骤可解决此方法,打开数据库里的Sql 查询编辑器窗口,运行以下的命令. 1.修改数据库为紧急模式 ALTER DATABASE 数据库名称 SET EMERGENCY 2.使数据库变为单用户模式 ALTER DATABASE 数据库名称 SET SINGLE_USER 3.修复数据库日志重新生成,此命令检查的分

TableViewCell的分割线左边没有空隙

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