gpt4 book ai didi

ios - 如何在 tableViewCell 周围添加 10px 的空间?

转载 作者:行者123 更新时间:2023-11-30 13:01:31 24 4
gpt4 key购买 nike

我正在尝试创建一个周围有 10px 间距的 tableViewCell,这样单元格就不会接触屏幕边缘。我尝试做类似的事情,我在 cellForRowAtIndexPath 的另一篇 stackOverflow 帖子中看到,但是当我在模拟器中运行它时,我得到的只是黑屏:

 cell.contentView.backgroundColor = UIColor.white

let whiteRoundedView : UIView = UIView(frame: CGRect(x: 10, y: 10, width: self.view.frame.size.width - 20, height: 188))

whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.8])
whiteRoundedView.layer.masksToBounds = false
whiteRoundedView.layer.cornerRadius = 10

cell.contentView.addSubview(whiteRoundedView)
cell.contentView.sendSubview(toBack: whiteRoundedView)

最佳答案

我认为最好从 Storyboard(或 xib)分配这 10px。您可以在 UIView 中插入前导空间约束(在 tableViewCell 中设计)。因此,您将自动不再使用经常出现问题的框架...

关于ios - 如何在 tableViewCell 周围添加 10px 的空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39862355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com