中原型单元格的左边距

中原型单元格的左边距

本文介绍了如何调整 UITableView 中原型单元格的左边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个 UITableViewController,例如通过 File → New Project... → iOS → Master-Detail Application 在 Xcode,一个 UITableViewcode> 是用原型单元创建的.

If I create a UITableViewController, for example via File → New Project... → iOS → Master-Detail Application in Xcode, a UITableView is created with a prototype cell.

生成的视图层次结构为:

The generated view hierarchy is:

在 Cell 的 Content UIView 左边缘和Title"文本的 UILabel 元素之间自动创建一个左边距",如下图橙色所示.

A left "margin" is automagically created between the Cell's Content UIView left edge and the "Title" text's UILabel element as shown below in orange.

这会在运行时在设备的屏幕边缘和 UILabel 文本之间产生相应的边距:

This results in a corresponding margin between the device's screen edge and the UILabel text at runtime:

那么,这个gap set的宽度在哪里,如何调整?

So, where is the width of this gap set, and how can it be adjusted?

大小检查器中 UILabel 的控件变灰:

The controls in the Size Inspector for the UILabel are greyed out:

我的首选选项是能够在 Interface Builder 中设置此间隙的宽度,但我也想了解此间隙的设置位置,以及如何以编程方式更改它.

My preferred option would to be able to set the width of this gap from within Interface Builder, but I would also like to understand where this gap is being set, and how to alter it programmatically.

推荐答案

你只需要设置 table view 的 contentInset 属性.您可以根据需要设置值.

You just need to set contentInset property of the table view. You can set value according to your need.

self.tableView.contentInset = UIEdgeInsetsMake(0, -15, 0, 0);

输出结果

这篇关于如何调整 UITableView 中原型单元格的左边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:35