我有一个 UIviewController,在 xib 文件中我添加了 3 个 uitableview 单元格,但我想给顶部和底部单元格提供类似于分组表外观的圆角。我该如何做到这一点,以及如何以编程方式将表格单元格添加到 uiviewcontroller?
问问题
168 次
1 回答
0
这是我的方法,但要使其工作,您需要有顶部单元格、底部单元格和中间单元格的图像。这将有助于区分第一行、中间行和底部行。
UIImage *rowBackground;
UIImage *selectionBackground;
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
if (indexPath.row == 0)
{
rowBackground = [UIImage imageNamed:@"topRow.png"]; //Top Rounded
selectionBackground = [UIImage imageNamed:@"topRowSelected.png"]; //Top Rounded Selected
}
else if (indexPath.row == sectionRows - 1)
{
if (indexPath.section == 0) {
rowBackground = [UIImage imageNamed:@"bottomRow.png"];// Bottom Rounded
selectionBackground = [UIImage imageNamed:@"bottomRowSelected.png"]; //Bottom Rounded Selected
} else {
rowBackground = [UIImage imageNamed:@"bottomRowSelected.png"];
selectionBackground = [UIImage imageNamed:@"bottomRow.png"];
}
}
else
{
rowBackground = [UIImage imageNamed:@"middleRow.png"]; // Anything in the middle
selectionBackground = [UIImage imageNamed:@"middleRowSelected.png"];
}
((UIImageView *)cell.backgroundView).image = rowBackground;
((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
于 2012-06-10T01:48:15.030 回答