如何给个人uitableviewcell圆形边框

时间:2012-06-10 01:14:51

标签: iphone ios xcode

我有一个UIviewController,在xib文件中我添加了3个uitableview单元格,但我想给出顶部和底部单元格圆角,类似于分组表格外观。我怎么能这样做,我怎样才能以编程方式将表格单元添加到uiviewcontroller?

1 个答案:

答案 0 :(得分: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;