
10.132014
XcodeでiPhone6/iPhone6 Plusを判別する方法です。
ウィンドウのスクリーンサイズを取得すれば判別が可能です。
コードは以下。
Objective-C
[swift]
CGRect r = [[UIScreen mainScreen] bounds];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if(r.size.height == 480){
// iPhone4
} else if(r.size.height == 568){
// iPhone5
} else if(r.size.height == 667){
// iPhone6
} else if(r.size.height == 736){
// iPhone7 Plus
}
} else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (r.size.height == 1024) {
// iPad
} else if (r.size.height == 1366) {
// iPad Pro
}
}
[/swift]
Swift
[swift]
let r:CGRect = UIScreen.main.bounds
if UIDevice.current.userInterfaceIdiom == .phone {
if r.size.height == 480 {
// iPhone4
} else if r.size.height == 568 {
// iPhone5
} else if r.size.height == 667 {
// iPhone6
} else if r.size.height == 736 {
// iPhone7 Plus
}
} else if UIDevice.current.userInterfaceIdiom == .pad {
if r.size.height == 1024 {
// iPad
} else if r.size.height == 1366 {
// iPad Pro
}
}
[/swift]
複雑なレイアウトのアプリの場合など、画面サイズに合わせてStoryBoardを用意し、AppDelegateでStoryBoardを読み込む際に使っています。
株式会社woodsmallの小林でした。
https://woodsmall.co.jp/
© 2012-2021 woodsmall inc. All rights reserved. woodsmall®は株式会社woodsmallの登録商標です。 商標登録第5574005号