分组 UITableView 中第一个和最后一个单元格的自定义圆角 [英] Custom rounded corners for first and last cell in a grouped UITableView

查看:70
本文介绍了分组 UITableView 中第一个和最后一个单元格的自定义圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 iPhone 应用程序当前显示一个包含 2 个部分的分组表格.我尝试使用以下方法更改每个部分的第一个和最后一个单元格(或在只有一行的部分的情况下在同一单元格上)的圆角半径:

My iPhone app is currently displaying a grouped table with 2 sections. I tried to change the radius of the rounded corners on the first and last cells of each section (or on the same cell in the case of sections with just one row) using:

cell.layer.cornerRadius = 4;

或作用于整个 tableview:

or acting on the whole tableview:

self.tableView.layer.cornerRadius = 4;

但没有运气...当然,我在执行此操作之前已经导入了 QuartzCore.看起来只有当表格以普通样式显示时才可以自定义角落.

but no luck...Of course I've imported QuartzCore before performing this operation. It looks like it's possible to customise the corners only when the table is displayed with plain style.

理想的解决方案是自定义第一个的顶角和最后一个的底角.

The ideal solution would be to customise top corners in the first one and bottom corners in the last.

有什么建议吗?

推荐答案

最简单的方法是:

  1. 在 xib 文件中制作自定义单元格,设置它们的唯一标识符,如:@"beginCell"、@"middleCell"、@"endCell".你可以按照这个教程来制作:http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder/

  1. Make a custom cells in a xib file, set their unique identifiers like: @"beginCell", @"middleCell", @"endCell". You can make it according to this tutorial: http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder/

方法中- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath您必须找到您在该部分的中间或开头/结尾处,并使用具有正确标识符的单元格.

In method - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath you have to find ejther you are in the middle or on begin/end of the section and use the cell with proper identifier.

这篇关于分组 UITableView 中第一个和最后一个单元格的自定义圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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