Mar*_*cin 17 objective-c uitableview ios autolayout ios8
UIViewController用UIView和UITableView
UIView
|-UITableView
Run Code Online (Sandbox Code Playgroud)
我正在尝试设置这样的边距:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.layoutMargins = UIEdgeInsetsMake(30, 30, 30, 30);
self.tableView.preservesSuperviewLayoutMargins = YES;
[self.view layoutIfNeeded];
}
Run Code Online (Sandbox Code Playgroud)
但是这个观点没有发生任何事情.
以下是InterfaceBuilder的约束
(lldb) po self.view.constraints
<__NSArrayM 0x786ab6e0>(
<NSLayoutConstraint:0x7896e940 UIView:0x7896e470.trailingMargin == UITableView:0x79b51a00.trailing - 16>,
<NSLayoutConstraint:0x7896e970 UITableView:0x79b51a00.leading == UIView:0x7896e470.leadingMargin - 16>,
<NSLayoutConstraint:0x7896e9a0 V:[_UILayoutGuide:0x7896e510]-(0)-[UITableView:0x79b51a00]>,
<NSLayoutConstraint:0x7896e9d0 V:[UITableView:0x79b51a00]-(0)-[_UILayoutGuide:0x7896e600]>,
<_UILayoutSupportConstraint:0x7896c7d0 V:[_UILayoutGuide:0x7896e510(0)]>,
<_UILayoutSupportConstraint:0x7896c2b0 V:|-(0)-[_UILayoutGuide:0x7896e510] (Names: '|':UIView:0x7896e470 )>,
<_UILayoutSupportConstraint:0x7896cbf0 V:[_UILayoutGuide:0x7896e600(0)]>,
<_UILayoutSupportConstraint:0x7896ea00 _UILayoutGuide:0x7896e600.bottom == UIView:0x7896e470.bottom>
)
Run Code Online (Sandbox Code Playgroud)
结果没有看到任何边缘,没有任何改变....我正在发布什么?
iOS 8
the*_*end 41
自定义layoutMargins不适用于作为UIViewController实例的根的视图.这些是由系统定义的,不能被覆盖.您需要添加另一个包含所有内容的子视图,然后可以修改此新"contentView"上的布局边距
更新:
讨论
使用此属性可指定视图边缘与任何子视图之间所需的空间量(以磅为单位).自动布局使用边距作为放置内容的提示.例如,如果使用格式字符串"| - [subview] - |"指定一组水平约束,则子视图的左右边缘将通过相应的布局边距从超级视图的边缘插入.当视图的边缘靠近超视图的边缘并且preservesSuperviewLayoutMargins属性为YES时,可能会增加实际的布局边距以防止内容与superview的边距重叠.
默认边距为每边八个点.
如果视图是视图控制器的根视图,则系统会设置和管理边距.顶部和底部边距设置为零点.侧边距取决于当前尺寸等级,但可以是16或20点.您无法更改这些边距.
Vik*_*era 13
这已经改变了iOS 11.在为此iOS版本进行部署目标设置时,自定义边距似乎运行良好.有一天,我们会嘲笑我们以前经历过的事情.
如果要设置低于系统最小值的值(可能因设备而异) - 您还必须设置viewRespectsSystemMinimumLayoutMargins为false(默认情况下为true).
如果你瞄准iOS 10并降低你的运气,那么@Reverend的回答是正确的 - 没有为viewcontroller的根视图定制边距.
| 归档时间: |
|
| 查看次数: |
16389 次 |
| 最近记录: |