LoginSignup
56
52

More than 5 years have passed since last update.

[Swift] 画面サイズ、statusBar、navigationBar、tabBarなどの高さを取得するのをまとめた

Last updated at Posted at 2016-03-29

目的

よく使う、statusBar、navigationBar、tabBarの高さや、画面サイズの取得をまとめた。

方法

import UIKit

struct DeviceSize {

    //CGRectを取得
    static func bounds() ->CGRect {
        return UIScreen.mainScreen().bounds
    }

    //画面の横サイズを取得
    static func screenWidth() ->Int {
        return Int(UIScreen.mainScreen().bounds.size.width)
    }

    //画面の縦サイズを取得
    static func screenHeight() ->Int {
        return Int(UIScreen.mainScreen().bounds.size.height)
    }

    static func statusBarHeight() -> CGFloat {
       return UIApplication.sharedApplication().statusBarFrame.height
    }

    static func navBarHeight(navigationController: UINavigationController) -> CGFloat {
        return navigationController.navigationBar.frame.size.height
    }

    static func tabBarHeight(tabBarController: UITabBarController) -> CGFloat {
        return tabBarController.tabBar.frame.size.height
    }

}
56
52
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
56
52