ios 有没有办法通过 Storyboard 设置 UITableView 的 contentInset?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25195100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:45:12  来源:igfitidea点击:

Is there a way to set a UITableView's contentInset through Storyboard?

iosuitableviewuistoryboard

提问by 3254523

self.tableView.contentInset = UIEdgeInsetsMake(232, 0, 232, 0)

is there a way of setting this in Storyboard?

有没有办法在 Storyboard 中设置它?

采纳答案by KudoCC

Yes, UITableView is subclass of UIScrollView, its contentInset property is the property of UIScrollView, so find it in the part of UIScrollView.

是的,UITableView 是 UIScrollView 的子类,它的 contentInset 属性是 UIScrollView 的属性,所以在 UIScrollView 的部分找到它。

enter image description here

在此处输入图片说明

For Xcode 6 updated:

对于 Xcode 6 更新:

enter image description here

在此处输入图片说明

I think the reason that I can set contentInsetin Xcode 6 is because the project is created before Xcode 6. So if a project is created in Xcode 6 and above, you can't set contentInset. I think that is because in iOS 7 UIViewControllerwill adjust this property accordingly. Look at automaticallyAdjustsScrollViewInsetsof UIViewController.

我觉得我可以contentInset在Xcode 6中设置的原因是因为项目是在Xcode 6之前创建的。所以如果一个项目是在Xcode 6及更高版本中创建的,则不能设置contentInset. 我认为这是因为在 iOS 7 中UIViewController会相应地调整此属性。看一下automatedAdjustsScrollViewInsetsof UIViewController

回答by Lars Blumberg

The content inset option seems to be gone from the attribute inspector since Xcode 6. But if you don't want to define contentInsetin code as it is user interface related, there's still an option left:

自 Xcode 6 以来,内容插入选项似乎从属性检查器中消失了。但是如果您不想contentInset在代码中定义它是与用户界面相关的,那么仍然有一个选项:

Select your UITableViewand open the Identity Inspector(Alt+Cmd+3) and click the plus button to add an user defined runtime attribute. Select Rectas its type and contentInsetas its key path.

您的选择UITableView并打开身份检查Alt+ Cmd+ 3),然后点击加号按钮添加一个用户定义的属性运行。选择Rect作为其类型和contentInset关键路径。

See example here that changes the top inset. 50appears to be stored as the xvalue but strangely it changes the top inset.

请参阅此处更改顶部插图的示例。50似乎被存储为x值,但奇怪的是它改变了顶部的插图。

Reference: {{top, left}, {bottom, right}}

参考: {{top, left}, {bottom, right}}

Setting content inset as user defined attributed

Setting content inset as user defined attributed

回答by Sylvain

In the XIB, the UIScrollView's contentInset keypath, the values are organized in the same order as the UIEdgeInsets constructor:

在 XIB 中,UIScrollView 的 contentInset 键路径中,值的组织顺序与 UIEdgeInsets 构造函数相同:

{{top, left}, {bottom, right}}

{{top, left}, {bottom, right}}

UIEdgeInsets(top: 100, left: 0, bottom: 100, right: 0)

UIEdgeInsets(top: 100, left: 0, bottom: 100, right: 0)