目次
アプリが表示されるディスプレイのサイズ
上記リンク先のAppleのガイドラインによると、2019年3月時点で4つのDisplay Sizeがあります。
種類 | height | width |
40mm(Series4) | 394px | 324px |
44mm(Series4) | 448px | 368px |
38mm(Series3以下) | 340px | 272px |
42mm(Series4以下) | 390px | 312px |
[追記: 2019.3.24]
Series4のスクリーンは角丸があるので、Content-safeエリアという区域内だけで表示できないとスクロールしないと全てを表示できなくなることもあるそうです。
[追記: ここまで]
たとえば画面サイズに応じてボタンの幅を変えたい
例 button1の幅を、button2の幅を基準に画面サイズに合わせて変更したい。
// InterfaceController.swift // watchOSTest WatchKit Extension class InterfaceController: WKInterfaceController { @IBOutlet var button1: WKInterfaceButton! @IBOutlet var button2: WKInterfaceButton! override func awake(withContext context: Any?) { super.awake(withContext: context) // Configure interface objects here. //画面サイズを取得 let watchWidth = self.contentFrame.width //button1の幅を指定 button1(watchWidth-100.0) // 100はbutton2の幅。 } }
こんな感じで実装できます。
ポイント
実行時にボタンのサイズを取得できないので、button2の幅はXcodeで指定し、幅を「Fixed」にする。
指定した数値を基準にbutton1の幅を指定する。