UIScreen サンプル
サンプルで動作を確認 コピーペーストで確認できます。
// 画面全体のサイズを取得します。
let mainBounds : CGRect = UIScreen.mainScreen().bounds
// 画面全体の横幅のサイズをポイントサイズで取得します。
let boundsWidth = mainBounds.width
// 画面全体の縦幅のサイズをポイントサイズで取得します。
let boundsHeight = mainBounds.height
// デバック表示
print(boundsWidth)
print(boundsHeight)
// ステータスバーの領域を除いた画面のサイズを取得します。
let mainApplicationFrame : CGRect = UIScreen.mainScreen().applicationFrame
// ステータスバーを除いた横幅のサイズをポイントサイズで取得します。
let mainApplicationFrameWidth = mainApplicationFrame.width
// ステータスバーを除いた縦幅のサイズをポイントサイズで取得します。
let mainApplicationFrameHeight = mainApplicationFrame.height
// デバック表示
print(mainApplicationFrameWidth)
print(mainApplicationFrameHeight)
UIScreen 概要
UIScreen クラスから画面のサイズ情報を取得します。
- Import Statement
import UIKit - Available
iOS 2.0 and later - Inherits
NSObject
おすすめの本