iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 7
2
Mobile Development

IOS App開發學習日誌系列 第 7

Day7 AutoLayout(一)

  • 分享至 

  • twitterImage
  •  

今天要來介紹在storyboard當中的autolayout功能
https://ithelp.ithome.com.tw/upload/images/20190923/20120980nALgAmS54a.png
上圖中我們可以看到一個button元件被放置在畫面的中間,但在不同devices上運行的時候,會發生位置跑版的情況
原因是因為不同裝置的尺寸並不相同,為此我們可以使用autolayout來解決這個問題

AutoLayout

Auto Layout是一個以約束條件為基礎的佈局系統(constraint-based layout system),它讓開發者能夠開發一個能自我調整型的UI,可以依照螢幕的尺寸以及裝置的方向來調整。

首先我們須先選取需要約束的元件,按住ctrl並拖曳至畫面空白處
接著將Center Horizontally in Safe Area以及Center Vertically in Safe Srea勾選起來
這麼做是為了確保元件的xy軸分別對準手機的xy軸正中間
https://ithelp.ithome.com.tw/upload/images/20190923/20120980yCkLOd4LwF.png
接著我們可以點進右方的show the size inspector進行位置的修改
https://ithelp.ithome.com.tw/upload/images/20190923/20120980wouH3Rbo53.png
修改Multiplier那個欄位便能修改約束條件
x軸的部分正中間為1,左右兩邊分別為0跟2
y軸的部分正中間為1,上下兩邊分別為0跟2
都是按比例調整放置位置
今天介紹先到這,明天會接續autolayout的其它用法


上一篇
Day6 Storyboard
下一篇
Day8 AutoLayout(二)
系列文
IOS App開發學習日誌30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言