6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【備忘録】Swiftで機種に応じてデザインを変える

Last updated at Posted at 2019-09-21

#機種に応じてデザインを変更する
機種ごとの画面サイズに応じたことをしたい時に、どうぞ。viewDidLoadの時点でも動くよ。(一応、どうしても身近に愛用している人がいなかったiPhone XS Maxを除き、実機テストで確認済み)

あ、機種ごとの性能の違いを考えて機種に応じた動作をさせたい時はこの方法はやめたほうがいい。あくまでも画面サイズに応じた対応をしたいときだけね(デザインとか)。

        //画面の高さ(ピクセル)で分けた
print(UIScreen.main.nativeBounds.height)

switch(UIScreen.main.nativeBounds.height) {
 
        case 1136:
            // iPhone 5, iPhone 5s, iPhone 5c, iPhone SE
            break

        case 1334:
            // iPhone 6, iPhone 6s, iPhone 7, iPhone 8
            break

        case 1920:
            // iPhone 6 Plus, iPhone 6s Plus, iPhone 7 Plus, iPhone 8 Plus
            break
            
        case 2436:
            //iPhone X,iPhone XS
            break
            
        case 1792:
            //iPhone XR
            break
            
        case 2688:
            //iPhone XS Max
            break
            
        default:
            break

        }
6
3
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
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?