【问题标题】:UITableViewCell's backgroundView and corner radius issue in grouped tablesUITableViewCell 在分组表中的 backgroundView 和圆角半径问题
【发布时间】:2013-06-17 10:49:08
【问题描述】:

我有一个分组UITableView,我已经将其中一个单元格的背景设置为渐变图像,这样:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"cell"];

   if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

      cell.textLabel.text = NSLocalizedString(@"Add item", @"");
      cell.textLabel.backgroundColor = [UIColor clearColor];

      UIImage* image1 =[[UIImage imageNamed:@"gradient_normal"] stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
      UIImage* image2 =[[UIImage imageNamed:@"gradient_selected"] stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
      cell.backgroundView = [[UIImageView alloc] initWithImage:image1];
      cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:image2];
   }

return cell;
}

单元格的背景已正确显示,但它不再有圆角,因为表格顶部和底部以及默认背景的其余单元格...我尝试设置 cornerRadius 属性表视图,但它没有工作。而且我无法为特定单元格设置cornerRadius

我发现的唯一一篇处理同样问题的帖子实际上并没有得到答复 (grouped tableViewCell - no rounded corner after setting the background of a grouped table cell),有人可以帮我解决这个问题吗?

提前致谢

【问题讨论】:

    标签: ios uitableview background rounded-corners


    【解决方案1】:

    如果您被允许/能够使用外部库,请查看PrettyKit,这很容易。

    如果你必须自己做,最好的办法是继承 UITableViewCell 并创建你自己的自定义单元格。这是一个很好的tutorial

    【讨论】:

    • 谢谢!首先我会尝试自己定制,但我会考虑你提到的库
    猜你喜欢
    • 1970-01-01
    • 2011-08-05
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 2016-07-10
    • 1970-01-01
    相关资源
    最近更新 更多