iOS的原生布局

// 按鈕高度60,左右等于邊,下距離安全區15

[NSLayoutConstraint activateConstraints:@[
        [button.heightAnchor constraintEqualToConstant:60],
        [button.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
        [button.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
        [button.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor constant:-15]
 ]];

// tableView的上下右等于邊,下邊距離安全區-100

[NSLayoutConstraint activateConstraints:@[
        [self.tableView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
        [self.tableView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
        [self.tableView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
        [self.tableView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor constant:-100]
]];
  • 需要注意的是
    布局的translatesAutoresizingMaskIntoConstraints屬性需要設置為NO
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Auto Layout是蘋果在iOS 6中引進的新技術,這是一種基于約束系統的布局規則,它的出現顛覆了開發人員創建...
    qiuyuliang閱讀 1,085評論 4 4
  • UIView可以說是我們日常工作中接觸最多的一個對象、是所有視圖控件(不包括視圖控制器)的基類。主要的功能包括視圖...
    kirito_song閱讀 4,028評論 1 33
  • 一.iPhone X尺寸問題 1. 高度增加了145pt,變成812pt. 2.屏幕圓角顯示,注意至少留10pt邊...
    騎行天下閱讀 12,924評論 5 36
  • 適配iOS11 ??蘋果官方文檔??蘋果官方視頻為了掙錢...哦??不是,為了廣大中國的開發者,蘋果官方文檔出了好多中文...
    philiha閱讀 1,176評論 1 50
  • 翻譯自“Auto Layout Guide”。 1 入門 1.1 理解自動布局 自動布局根據視圖層級結構中視圖上的...
    lakerszhy閱讀 3,683評論 3 26