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
Is there a way to set a UITableView's contentInset through Storyboard?
提问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 的部分找到它。
For Xcode 6 updated:
对于 Xcode 6 更新:
I think the reason that I can set contentInset
in 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 UIViewController
will 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 contentInset
in code as it is user interface related, there's still an option left:
自 Xcode 6 以来,内容插入选项似乎从属性检查器中消失了。但是如果您不想contentInset
在代码中定义它是与用户界面相关的,那么仍然有一个选项:
Select your UITableView
and open the Identity Inspector(Alt+Cmd+3) and click the plus button to add an user defined runtime attribute. Select Rect
as its type and contentInset
as its key path.
您的选择UITableView
并打开身份检查(Alt+ Cmd+ 3),然后点击加号按钮添加一个用户定义的属性运行。选择Rect
作为其类型和contentInset
关键路径。
See example here that changes the top inset. 50
appears to be stored as the x
value but strangely it changes the top inset.
请参阅此处更改顶部插图的示例。50
似乎被存储为x
值,但奇怪的是它改变了顶部的插图。
Reference: {{top, left}, {bottom, right}}
参考: {{top, left}, {bottom, right}}
回答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)