gpt4 book ai didi

swift - 如何将 UITableViewCell 设置为屏幕的全宽?

转载 作者:可可西里 更新时间:2023-11-01 00:57:36 25 4
gpt4 key购买 nike

描述:

如下图所示,这里是一个自定义的 UITableViewCell 被聚焦了。

width not full

聚焦时,我将其 contentView 的背景色设置为黑色,如下所示:

//Where next is the next cell being focused.
next.contentView.backgroundColor = UIColor.black

此外,当我通过 StoryBoard 检查 contentView 的宽度时,它清楚地显示“1904”而不是预期的“1920”。它是灰色的,我不能修改它。

此时很明显,contentView 没有占据整个屏幕的宽度。

我尝试过的:

我经历了多种不同的可能性。

我一开始以为是和tableView的contentInset有关:

//Inside my tableView controller
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0)

然后我以为是tableCell的布局边距:

//Inside my custom UITableCell
self.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0)

然后我尝试更改 UITableCell 的 contentView 框架:

//Inside my custom UITableCell
self.contentView.frame = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(0, 0, 0, 0))

我终于尝试了某种形式的 self.frameself.contentView.frame:

//In my UITableCell
self.contentView.frame = CGRect.init(x: self.bounds.maxX, y: self.bounds.maxY, width: self.bounds.width + 100, height: self.bounds.height)

问题:

如何将UITableViewCell设置为全屏宽度?

截图:

/image/mAoUh.png

显示我的 tableviewcell 的 contentView 边距的图像(它们与 tableviewcells 相同)

/image/20X74.png

图片展示了我如何为我的 tableView 添加对齐约束。

(帖子太大,链接原因)

最佳答案

鉴于您正在使用 UITableViewController,您几乎无法控制其行为,也无法控制 Controller 内 tableView 的约束。我建议您在 UIViewController 中切换 tableView,注意将约束设置为 super View 的前导和尾随,而不是其边距。

关于swift - 如何将 UITableViewCell 设置为屏幕的全宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42064300/

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