如何将 UITableViewCell 设置为屏幕的全宽?
How to set UITableViewCell to the full width of screen?
描述:
如下图可以看到,这里是一个自定义的UITableViewCell,它是有焦点的。
聚焦时,我将其 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的layout margin:
//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.frame
和 self.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
为屏幕全宽?
截图:
https://i.stack.imgur.com/mAoUh.png
图像显示我的 tableviewcell 的 contentView 的边距(它们与 tableviewcells 相同)
https://i.stack.imgur.com/20X74.png
显示如何为 tableView 添加对齐约束的图像。
(对于 post 来说太大了,link 的原因)
鉴于您正在使用 UITableViewController,您几乎无法控制它的行为,并且 none 无法控制控制器内 tableView 的约束。
我建议你在 UIViewController 中切换一个 tableView,注意将你的约束设置为 superview 的前导和尾随,而不是它的边距。
描述:
如下图可以看到,这里是一个自定义的UITableViewCell,它是有焦点的。
聚焦时,我将其 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的layout margin:
//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.frame
和 self.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
为屏幕全宽?
截图:
https://i.stack.imgur.com/mAoUh.png
图像显示我的 tableviewcell 的 contentView 的边距(它们与 tableviewcells 相同)
https://i.stack.imgur.com/20X74.png
显示如何为 tableView 添加对齐约束的图像。
(对于 post 来说太大了,link 的原因)
鉴于您正在使用 UITableViewController,您几乎无法控制它的行为,并且 none 无法控制控制器内 tableView 的约束。 我建议你在 UIViewController 中切换一个 tableView,注意将你的约束设置为 superview 的前导和尾随,而不是它的边距。