[Swift] スクリーンサイズを取得する
公開日:
:
iPhone App 開発, Swift
Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
スクリーンサイズを取得
iPhoneの幅と高さを取得する関数を紹介します。
iOS8から画面の傾きでのUIScreenの幅・高さが反映されるようになったのでiOSのバージョンにより判断が必要になりました。
func getScreenSize() -> CGSize { let screenSize = UIScreen.mainScreen().bounds.size; if NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1 && UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation) { return CGSizeMake(screenSize.height, screenSize.width) } return screenSize }
2行目でスクリーンサイズを取得。
3・4行目でiOSのバージョンと画面の傾きを判断します。
戻り値はCGSizeです。
高さを取得する場合はCGSize.height。
幅を取得する場合はCGSize.width。
ad
関連記事
-
-
[Swift] プロパティリスト(plist)を使ってCoreDataで一括登録する
プロパティリストを使う 初期データやあらかじめ用意したデータを一括登録したい場合、プロパティリスト
-
-
[Swift] UINavigationControllerで戻るイベントを取得する
UINavigationController UINavigationControllerを使用し
-
-
[iPhone App]WorkManager アップデートしました。
Processing For App Storeでやきもきした僕です。こんにちわ。 今
-
-
[Objective-C] no architectures to compile for … のコンパイルエラーについて
起動したプロジェクトでコンパイルエラーが出ました。 no architectures to com
-
-
[Swift] ビルド時のエラー&iOS8でNSBigDecimalのバグ
ビルド時のエラー Swiftプロジェクトを実行中に以下のエラーが出ました。 "__TFSs15_
-
-
[Objective-C] バージョン更新時に変更内容をアラートで出力する
アプリの更新内容を表示したい! バージョン更新時に変更内容を表示させたいのは、ユーザーがいちいちA
-
-
[Swift] 関数型プログラミング
関数型プログラミングについて、ストーリー仕立ての面白い記事がありましたので紹介します。 IQ1
-
-
[Swift] Swiftでいろんなfor文まとめてみた
いろんなfor文 プログラム作成で必ず出てくるfor文を自分なりにまとめてみました。 Swift