場景:UIViewController
上添加 UITableView
以下主要講的是通過storyboard上直接對控件進(jìn)行約束約束锨用,實(shí)現(xiàn)方法有很多種汹桦,我一般用以下方法實(shí)現(xiàn):
Xcode 9之前
constraint1.png
然后直接在iPhone x上運(yùn)行闸婴,效果圖1:
Simulator Screen Shot - iPhone X - 1.png
很顯然效果不是我想要的嘿歌,解決方法看圖操作:
雙擊bottom約束
constraints2.png
將
Bottom Layout Guide
改成 superView
constraints3.png
再運(yùn)行結(jié)果如圖2:
Simulator Screen Shot - iPhone X - 2 .png
完美解決0砝АG砬弧!
Xcode9之后
就用Safe Area Layout Guide
替代了原來的Top/Bottom Layout Guide
斟叼,前提是最低支持ios 9
版本才能用使用Safe Area Layout Guide
.
選中Main.storyboard
偶惠,然后勾選User Safe Area Layout Guide
,就可以將整個(gè)storyboard的頁面都添加safe area朗涩,如下圖:
constraints4.png
xcode會自動幫我們轉(zhuǎn)換過來忽孽,上面約束圖1就變成了以下:
constraints5.png
運(yùn)行之后會發(fā)現(xiàn)效果跟圖1是一樣,再重得上面的步驟:
雙擊bottom約束
constraints6.png
將
Safe Area
改成 superView
constraints7.png
運(yùn)行效果就跟圖2一樣啦谢床!