Xcode 4.4.1 の Interface Builder は、iPhone 5 の画面に対応したサイズになっていません。しかし、Autosizing を活用することで、ソースコードで場合分けすることなく、iPhone 5 にも対応したデザインをある程度作成できます。
今回は、ボタンを5つ並べた次のようなデザインで、Autosizing の動作を検証してみます。
これまでの画面では、Autosizing を変更しても、配置や大きさに変化はありませんでした。しかし、iPhone 5 の液晶サイズに拡大されたときは、Autosizing の設定によって、下記のように配置や大きさに違いが生じます。
Autosizing については、Interface Builder User Guide(現在は公開されていないようです。)に記載があります。
The springs and struts in the autosizing control define the selected view’s relationship to its parent frame. A spring causes the view to resize itself proportionally based on the width or height of its superview. A strut causes the view to maintain a fixed distance between itself and its superview along the given edge.
Spring が中央の上下左右の矢印で、Strut が周囲の上下左右のエの字を示しています。Spring は、オブジェクトが拡大可能か拡大不可能かの制約になります。Strut は、設定された側の画面端からの距離が固定される制約になります。
Autosizing を活用して、iPhone 3G から iPhone 5 まで対応したアプリを開発しましょう。
参考文献