【移动应用开发技术】iOS如何使用UITableView设置全屏分隔线_第1页
【移动应用开发技术】iOS如何使用UITableView设置全屏分隔线_第2页
【移动应用开发技术】iOS如何使用UITableView设置全屏分隔线_第3页
【移动应用开发技术】iOS如何使用UITableView设置全屏分隔线_第4页
【移动应用开发技术】iOS如何使用UITableView设置全屏分隔线_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】iOS如何使用UITableView设置全屏分隔线

1.自定义cell,手动添加分割线tableView.separatorStyle

=

UITableViewCellSeparatorStyleNone;//

自绘分割线

-

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

}2.重写cell的setFrame方法,高度-1,露出背景色-

(void)setFrame:(CGRect)frame

{

frame.size.height

-=

1;

//

给cellframe赋值

[super

setFrame:frame];

}//

取消系统分割线

self.tableView.separatorStyle

=

UITableViewCellSeparatorStyleNone;

//

设置tableView背景色

self.tableView.backgroundColor

=

[UIColor

colorWithWhite:215

/

255.0

alpha:1];3.利用系统属性设置(separatorInset,layoutMargins)共需添加三句代码:-(void)viewDidLoad

{

[super

viewDidLoad];

//1.调整(iOS7以上)表格分隔线边距

if

([self.tableView

respondsToSelector:@selector(setSeparatorInset:)])

{

self.tableView.separatorInset

=

UIEdgeInsetsZero;

}

//2.调整(iOS8以上)view边距(或者在cell中设置preservesSuperviewLayoutMargins,二者等效)

if

([self.tableView

respondsToSelector:@selector(setLayoutMargins:)])

{

self.tableView.layoutMargins

=

UIEdgeInsetsZero;

}

}对cell的LayoutMargins属性的设置-(UITableViewCell

*)tableView:(UITableView

*)tableView

cellForRowAtIndexPath:(NSIndexPath

*)indexPath

{

static

NSString

*ID

=

@"cell";

FSDiscoverSpecialCell

*cell

=

[tableView

dequeueReusableCellWithIdentifier:ID];

if

(cell

==

nil)

{

cell

=

[[FSDiscoverSpecialCell

alloc]

initWithStyle:UITableViewCellStyleSubtitle

reuseIdentifier:ID];

}

//2.调整(iOS8以上)tableView边距(与上面第2步等效,二选一即可)

if

([cell

respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)])

{

cell.preservesSuperviewLayoutMargins

=

NO;

}

//3.调整(iOS8以上)view边距

if

([cell

respondsToSelector:@selector(setLayoutMargins:)])

{

[cell

setLayoutMargins:UIEdgeInsetsZero];

}

return

cell;

}三种方法优缺点比较:-(void)viewDidLoad

{

[super

viewDidLoad];

if

([self.tableView

respondsToSelector:@selector(setSeparatorInset:)])

{

[self.tableView

setSeparatorInset:UIEdgeInsetsZero];

}

if

([self.tableView

respondsToSelector:@selector(setLayoutMargins:)])

{

[self.tableView

setLayoutMargins:UIEdgeInsetsZero];

}-

(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];

}

}@property

(nonatomic)

UIEdgeInsets

separatorInset

NS_AVAILABLE_IOS(7_0)

UI_APPEARANCE_SELECTOR;

//

allows

customization

of

the

frame

of

cell

separators@property

(nonatomic)

UIEdgeInsets

layoutMargins

NS_AVAILABLE_IOS(8_0);/upload/information/20200623/126/120715.jpgPS:附效果图如下:/upload/information/20200623/126/120716.png/upload/information/20200623/126/120717.png/upload/information/20200623/126/120718.png/upload/information/20200623/126/120719.png附:设置UITableView的单元格分割线离屏幕左右的距离为0/upload/information/20200623/126/120720.pngif

([_tableView

respondsToSelector:@selector(setSeparatorInset:)])

{

[_tableView

setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];

}

if

([_tableView

respondsToSelector:@selector(setLayoutMargins:)])

{

[_tableView

setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];

}//代理方法

-(void)tableView:(UITableView

*)tableView

willDisplayCell:(UITableViewCell

*)cell

forRowAtIndexPath:(NSIndexPath

*)indexPath

{

if

([cell

respondsToSelector:@selector(setSeparat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论