[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で一括登録する
プロパティリストを使う 初期データやあらかじめ用意したデータを一括登録したい場合、プロパティリスト
-
-
[Objective-C] no architectures to compile for … のコンパイルエラーについて
起動したプロジェクトでコンパイルエラーが出ました。 no architectures to com
-
-
[Swift] UINavigationControllerで戻るイベントを取得する
UINavigationController UINavigationControllerを使用し
-
-
[Objective-C] デリゲート (Delegate)を理解する!
デリゲートとは? デリゲートに関しての意味合いとして、”委譲”とか”代理”と説明されることが多いで
-
-
[Swift] ビルド時のエラー&iOS8でNSBigDecimalのバグ
ビルド時のエラー Swiftプロジェクトを実行中に以下のエラーが出ました。 "__TFSs15_
-
-
[Objective-C] 小数点を丸める!(数値変換)
小数点を含む数値 Objective-Cに限らず、小数点を含む数値を計算する場合はdoubleやf
-
-
[Swift] CoreDataを使ってみる
SwiftでCoreData 今回はSwiftでCoreDataを使ってみます。 Xcodeプロ
-
-
iPhoneApp WorkManager公開されました!
きっとリジェクトされるんだろうなと思いながら申請を出して1週間。 本日、公開のメールが届きまし
-
-
[Swift] frameworkについて
先日、Swiftで実装されたライブラリをまとめたサイトを発見しました。 Swift Toolb