ios - 需要有关 UITableViewCell SeparatorInset 的帮助

标签 ios objective-c uitableview

1> 我的 tableview 中有 UITableViewCellUITableViewCell subclass cell。在 UITableViewCell 子类单元格 上设置 SeparatorInset 不起作用?但是如果我在 UITableViewCell 上设置它就可以正常工作。

2> 关于 SeparatorInset 的 Apple 文档说:

You can use this property to add space between the current cell’s contents and the left and right edges of the table. Positive inset values move the cell content and cell separator inward and away from the table edges. Negative values are treated as if the inset is set to 0.

Only the left and right inset values are respected; the top and bottom inset values are ignored. The value assigned to this property takes precedence over any default separator insets set on the table view.

一个。如果我在 UITableViewCell 上设置 [cell setSeparatorInset:UIEdgeInsetsMake(0, 100, 0, 0)]; 它会将内容向右推

但是在 UITableViewCell 上设置 [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 100)]; 只会将分隔符推向左侧而不是内容,为什么?

最佳答案

1)

UITableViewCell 中,您有无法直接编辑的 subview (标题、附件 View 等)。 separatorInset 使您能够调整这些 subview 的位置(换句话说,separatorInset 在这些 subview 的位置计算期间被考虑在内)。

在自定义 UITableViewCell 子类中,您定位自己的 subview ,因此除非您在计算它们的位置时特别考虑 separatorInset,否则它没有任何效果。

2)

separatorInset 不会将内容“推”到左/右,而是将(虚拟)插图添加到它们所在的容器中。所以如果例如您只有标题不会拉伸(stretch)到单元格的全宽 (-100) 添加右插图后您不会看到任何差异。

关于ios - 需要有关 UITableViewCell SeparatorInset 的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29227372/

相关文章:

iphone - 如何从图像显示视频

ios - TableView 快速复制同一标签的多个副本

swift - 如何从 UITableViewRowAction 更改特定单元格的字体颜色?

iphone - Xcode 4 - 使用正则表达式的查找器

ios - 关闭 Cupertino 对话 Action Flutter

iphone - 可以在没有真实设备的情况下测试 iPhone 应用程序吗?

IOS 9 View 在底部被截断

objective-c - 哪个是调用 stringWithFormat 时长期使用的正确说明符?

ios - UIImage 未显示在 TableView 中

iphone - 如何将来自服务器的图像设置为矩形按钮的背景图像