美文网首页
浅析LayoutGuide

浅析LayoutGuide

作者: lanmoyingsheng | 来源:发表于2018-05-28 14:38 被阅读9次
iOS7:topLayoutGuide/bottomLayoutGuide

这两个是UIViewController的rootview的子视图。两个隐藏的占位视图,为了适配NavBar、TabBar、ToolBar而产生视图。

iOS9: UILayoutGuide

一种新AutoLayout的形式。

// 创建
UILayoutGuide *layoutGuide = [[UILayoutGuide alloc] init];
// 需要使用UIView的addLayoutGuide方法添加新建的layoutGuide
[someView addLayoutGuide:layoutGuide];
// 正式的约束代码
[layoutGuide.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:64].active = YES;
[layoutGuide.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
[layoutGuide.widthAnchor constraintEqualToConstant:250].active = YES;
[layoutGuide.heightAnchor constraintEqualToConstant:200].active = YES;

比NSLayoutConstraint书写更简洁。

iOS11: safeAreaLayoutGuide及Safe Area

safeAreaLayoutGuide系统自动创建。

相关文章

网友评论

      本文标题:浅析LayoutGuide

      本文链接:https://www.haomeiwen.com/subject/ypkgjftx.html