如何在 UITableview 的最后一个单元格中修改按钮的尾随空间? [英] How to modify the trailing space of a button in the last cell of a UITableview?

查看:20
本文介绍了如何在 UITableview 的最后一个单元格中修改按钮的尾随空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 UITableView 的最后一个单元格分隔符取全长(我的表格有 20 行)

I wanted to have the last cell separator of my UITableView to take the full length (my table has 20 rows)

我使用了这个代码:

if indexPath.row == 19 {
   cell.separatorInset = UIEdgeInsetsZero
   cell.layoutMargins = UIEdgeInsetsZero
   cell.preservesSuperviewLayoutMargins = false
} else {
   cell.preservesSuperviewLayoutMargins = true
}

我得到了想要的结果,但有点小故障.

I got the desired result, with a little glitch.

基本上,我在每个单元格的右侧都有一个按钮当我使用上述解决方案时,最后一个单元格中的按钮向左移动了一点(我假设由于线条移动了,按钮也移动了).所以现在除了修改的最后一个单元格中的最后一个按钮之外,所有按钮都对齐了.

Basically, I have a button on the right side of every cell and when I used the above solution, the button in the last cell moved a little bit to the left (I assume that since the line moved, the button also moved). So now all the buttons are aligned except the last button in the modified last cell.

问题:

有没有办法修改最后一个单元格中按钮的尾随空格?

Is there a way to modify the trailing space of the button in the last cell?

推荐答案

事情来了.

你用约束来定位这个东西.但是当你这样做时,你没有意识到你是通过约束边缘而不是单元格的绝对边缘来定位它的.

You positioned this thing with a constraint. But when you did that, you didn't realize you were positioning it with a constraint to the margin, not to the absolute edge of the cell.

但是当我们更改那个单元格的边距相关值时,我们移动了边距.所以按钮随之移动.

But when we changed the margin-related values for that one cell, we moved the margin. So the button moved with it.

解决方案:返回到 xib 文件并更改该约束,使其与单元格的边缘有关,而不是边距.现在它不会受到边距变化的影响,所有单元格看起来都一样.

Solution: go back into the xib file and change that constraint so it is with respect to the edge of the cell, not the margin. Now it won't be affected by the change in the margin, and all the cells will look the same.

这篇关于如何在 UITableview 的最后一个单元格中修改按钮的尾随空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆