iOS如何去除UITableView底部ios 去掉多余分割线的分割线

iOS9 设置UITableView 的分割线从顶端开始(去掉15像素) - 简书
iOS9 设置UITableView 的分割线从顶端开始(去掉15像素)
1、初始化数据
#import "ViewController.h"
@interface ViewController ()&UITableViewDataSource,UITableViewDelegate&
@property (nonatomic , strong) UITableView *myTableV
@property (nonatomic , strong) NSMutableArray *dataS
@implementation ViewController
- (UITableView *)myTableView{
if (_myTableView == nil) {
_myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_myTableView.delegate =
_myTableView.dataSource =
[self.view addSubview:_myTableView];
return _myTableV
- (NSMutableArray *)dataSources{
if (_dataSources == nil) {
_dataSources = [NSMutableArray arrayWithArray:@[@"第1行",@"第2行",@"第3行",@"第4行",@"第5行",@"第6行",@"第7行",@"第8行",@"第9行",@"第10行",@"第11行",@"第12行",@"第13行",@"第14行",@"第14行",@"第15行",@"第16行",@"第17行",@"第18行",@"第19行",@"第20行",@"第21行",@"第22行",@"第23行"]];
return _dataS
2、关键一,在viewDidLoad方法里,加入以下代码:
- (void)viewDidLoad {
[super viewDidLoad];
[self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
if ([self.myTableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.myTableView setSeparatorInset:UIEdgeInsetsZero];
if ([self.myTableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.myTableView setLayoutMargins:UIEdgeInsetsZero];
UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataSources.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.textLabel.text = self.dataSources[indexPath.row];
3、关键二,重写cell WillDisplay方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
iOS软件工程师UITableView删除cell分割线
来源:博客园
UITableView是UITableViewStylePlain风格的,这样整个TableView都会被分割线分隔开,不管有没有数据,非常丑。 为了可以自定义cell的分割线; 解决方案: 将UITableView的separatorStyle属性设置为UITableViewCellSeparatorStyleNone即可,如下: tableView.separatorStyle = UITableViewCellSeparatorStyleN
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动28422人阅读
iphone(78)
第一种方法
-(void)setExtraCellLineHidden: (UITableView *)tableView
&&&&UIView *view = [UIView new];
&&&&view.backgroundColor = [UIColor clearColor];
&&&&[tableView setTableFooterView:view];
&&&&[view release];
- (void)viewDidLoad
& & [super&viewDidLoad];
& & //设置tableView不能滚动
& & [self.tableView&setScrollEnabled:NO];
& & //在此处调用一下就可以啦 :此处假设tableView的name叫:tableView
& & [self&setExtraCellLineHidden:self.tableView];
在iOS4.3和iOS5.0中通过:值得注意的是在iOS4.3中可以直接设置footer为nil,但是在5.0不行,因为UITableView会默认生成一个Footer。(详见iOS Release Notes中的说明:Returning nil from the tableView:viewForHeaderInSection: method (or its footer equivalent) is no longer sufficient to
hide a header. You must override tableView:heightForHeaderInSection: and return 0.0 to hide a header.)
plain类型的tableview当显示的数据很少时,下面的cell即使不显示数据也会有分割线,可以通过下面这个函数去掉多余的分割线。
- (void)setExtraCellLineHidden: (UITableView&*)tableView
& &&UIView&*view =[ [UIView&alloc]init];
& & view.backgroundColor&= [UIColor&clearColor];
& & [tableView&setTableFooterView:view];
& & [view&release];
当tableview的dataSource为空时,也就是没有数据可显示时,该方法无效,只能在numberOfRowsInsection函数,通过判断dataSouce的数据个数,如果为零可以将tableview的separatorStyle设置为UITableViewCellSeparatorStyleNone去掉分割线,然后在大于零时将其设置为
UITableViewCellSeparatorStyleSingleLine
第二种方法
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Drawing our own separatorLine here because I need to turn it off for the
// last row. I can only do that on the tableView and on on specific cells.
// The y position below has to be 1 less than the cell height to keep it from
// disappearing when the tableView is scrolled.
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];
[separatorLine release];
// Setup default cell setttings.
UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];
separatorLine.hidden = NO;
// In the cell I want to hide the line, I just hide it.
seperatorLine.hidden = YES;
In viewDidLoad:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:594167次
积分:5472
积分:5472
排名:第4775名
原创:78篇
转载:50篇
评论:44条
(1)(1)(1)(4)(1)(3)(1)(3)(1)(2)(8)(3)(3)(6)(8)(6)(4)(7)(44)(11)(3)(3)(4)iOS应用开发中UITableView的分割线的一些设置技巧
作者:ForeverYoung21
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了iOS应用开发中UITableView分割线的一些设置技巧,包括消除分割线的方法,示例代码为传统的Objective-C语言,需要的朋友可以参考下
对于ios7,ios8及以上来说,调整UITableView的cell的分割线位置已经是相当不便,因为UITableView内部使用了margin layout.
其实只需要如下这样子就可以实现分割线的控制。
-(void)tableView:(UITableView )tableView willDisplayCell:(UITableViewCell )cell forRowAtIndexPath:(NSIndexPath *)indexPath
&&& // 下面这几行代码是用来设置cell的上下行线的位置
&&& if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
&&& [cell setLayoutMargins:UIEdgeInsetsZero];
&&& //按照作者最后的意思还要加上下面这一段,才能做到底部线控制位置,所以这里按stackflow上的做法添加上吧。
&&& if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
&&&&&&& [cell setPreservesSuperviewLayoutMargins:NO];
如果要直接使用TableView的sectionTitle,但又想设置它的字体,颜色什么的,可以使用如下方法。
- (void)tableView:(UITableView )tableView willDisplayHeaderView:(UIView )view forSection:(NSInteger)section
// Background color
view.tintColor = [UIColor blueColor];
// Text Color
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)
[header.textLabel setTextColor:[UIColor redColor]];
// 另一种方法设置背景颜色
// header.contentView.backgroundColor = [UIColor blackColor];
不显示分割线
通过tableFooterView修改UITableView分割线:
在使用UITableView的时候,如果没有数据/数据很少,会发现即使没有数据的cell也会有分割线,这样看起来并不美观,通常我们希望只有显示数据的cell会显示对应的分割线,而不显示数据的cell不显示分割线。
常用的做法有两种:
第一种做法是首先取消显示分割线,然后自定义cell,在cell的最底部加上一个高度为1的view,这样看起来就像是一条分割线。只有cell有数据显示出来的时候才会显示这个view,这样就达到了目的。
第二种做法既不用取消显示分割线,也不需要自定义cell,而是直接这样做:
self.tableView.tableFooterView = [[UIView alloc] init];
运行显示结果,发现就已经达到了我们的目的。很明显这种做法更方便。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具UITableView每个cell之间的默认分割线如何去掉 - 我是愤怒 - ITeye博客
博客分类:
刚刚才遇见这个问题,让自己很尴尬.
很简单,只需要
tableView.separatorStyle
浏览 16854
jinchishuxue
浏览: 236980 次
来自: 北京
,就这么简单。。。 不过还真行,不明白为什么不需要配jaa_ ...
其实应该是 ableView.separatorStyle = ...
armywin 写道http://www.buildapp.n ...

我要回帖

更多关于 ios 去掉多余分割线 的文章

 

随机推荐