




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 财务分析的意义和内容说课稿-2025-2026学年中职专业课-财务管理-财经类-财经商贸大类
- unit 7 Today is Monday教学设计-2025-2026学年小学英语四年级下册北师大版(一起)
- 第1课 寻根之旅教学设计-2025-2026学年初中艺术·美术人教版2024七年级下册-人教版2024
- 幼儿的社会行为与道德发展说课稿-2025-2026学年中职专业课-幼儿心理学-学前教育类-教育与体育大类
- 外研版八年级上册英语全册教学设计(配2025年秋改版教材)
- 跳动的琴弦(欣赏 阳光照耀着塔什库尔)教学设计-2025-2026学年小学音乐西师大版五年级上册-西师大版
- 蓄电池知识培训内容课件
- 2025年天津市红桥区中考三模物理试题(解析版)
- 2025年四川省资阳市中考英语试卷(含答案与解析)
- 第1章 生命的世界说课稿-2025-2026学年初中生物学北师大版七年级上册-北师大版
- 调相机工程施工质量验收规程-第4部分-仪表与控制系统
- 四渡赤水(课件)
- 2024年浙江绍兴杭绍临空示范区开发集团有限公司招聘笔试真题
- 部编版五年级语文上册各单元作文范文
- 贵州省贵阳市(2024年-2025年小学五年级语文)统编版小升初真题(上学期)试卷及答案
- 2024-2025学年青岛版七年级数学上册第一次单元过关检测 (前两章)
- 苏少版七年级上册综合实践活动教案
- 院前急救技能竞赛(驾驶员)理论考试题库大全-上(选择题)
- 锁骨骨折的护理查房
- 部编人教版六年级上册语文全册教学课件+单元复习课件
- 《消费心理学》课程教学大纲
评论
0/150
提交评论