UITableView 部分边框 [英] UITableView section border

查看:25
本文介绍了UITableView 部分边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 UITableView 部分(组样式)上设置边框?我的意思不是更改该部分中单元格的边框 - 我想要整个部分的边框.像这样:

Is there any way to set a border on a UITableView section (group style)? I don't mean change the border on the cells in the section - I want a border around the whole section. Like this:

注意:虽然上图只显示了一个部分的一部分,但所讨论的表格实际上有多个部分,每个部分的长度都可变,我想分别对这些部分进行边框.

Note: While the picture above only shows part of a single section, the table in question actually has multiple sections, each of variable lengths, which I would like to border separately.

推荐答案

是的,你可以用几行代码来实现:

Yes you can achieve it with couple of line of codes :

只需在您的 Xib 文件中包含 TableView.无需将 UITableView 样式设置为分组.

Simply have the TableView in your Xib file.No need to have the UITableView Style to Grouped.

1) 在 .h 文件中导入 QuartzCore 框架.

1) Import the QuartzCore framework in your .h file.

#import <QuartzCore/QuartzCore.h>

2) 现在在 .m 文件中设置 TableView 的图层.

2) Now set the Layers of the TableView in .m file.

[CategoryTblView.layer setBorderWidth: 1.0];
[CategoryTblView.layer setCornerRadius:8.0f];
[CategoryTblView.layer setMasksToBounds:YES];
[CategoryTblView.layer setBorderColor:[[UIColor blackColor] CGColor]];

这是输出:

这篇关于UITableView 部分边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆