【问题标题】:Is there a better solution to rounded corners in UITableview cell than this one?UITableview 单元格中的圆角是否有比这个更好的解决方案?
【发布时间】:2023-03-22 21:15:01
【问题描述】:

我试图将每边的每个单元格间距设置为 5,然后使角变圆。

到目前为止我有这个:

 override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 100.0;
    }

    override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

        cell.contentView.backgroundColor = UIColor.clearColor()
        var whiteRoundedView : UIView = UIView(frame: CGRectMake(0, 10, self.view.frame.size.width, 70))
        whiteRoundedView.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), [1.0, 1.0, 1.0, 1.0])
        whiteRoundedView.layer.masksToBounds = false
        whiteRoundedView.layer.cornerRadius = 3.0
        whiteRoundedView.layer.shadowOffset = CGSizeMake(-1, 1)
        whiteRoundedView.layer.shadowOpacity = 0.5
        cell.contentView.addSubview(whiteRoundedView)
        cell.contentView.sendSubviewToBack(whiteRoundedView)
    }

这将使每个单元格的宽度为 100%,这是我不想要的,因为我也想要两侧的空间。

滚动长列表时也感觉有点迟钝。

那么有更好的解决方案吗?

【问题讨论】:

    标签: ios swift uitableview


    【解决方案1】:

    一个小技巧:自定义您的表格视图单元格,将主视图添加到您的单元格的内容视图,您为此主视图设置边距和角半径,假设您希望两个单元格之间的间距为 6,然后您设置您的主视图 3将边距指向单元格内容视图的顶部和底部

    【讨论】:

    • 酷,所以或多或少,在每个单元格内放置一个 uiview 并设置该 uiview 的样式?但是如何去除细胞系/插图?是否可以在情节提要中的每个单元格之间添加间距?我会尽快接受你的回答
    • self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None 做到了
    • 是的。并且没有直接的方法可以在 Nib 中或以编程方式设置单元格之间的间距,但是您可以按照我所说的那样在单元格内布局视图,使其就像彼此之间有间距一样。
    猜你喜欢
    • 2017-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 2013-10-22
    • 2013-09-05
    • 1970-01-01
    相关资源
    最近更新 更多