LoginSignup
23
23

More than 5 years have passed since last update.

Storyboardで3.5inchディスプレイに手っ取り早く対応する。

Last updated at Posted at 2014-04-07

実行時にiPadとiPhoneのStoryboardを読み分けるのはプロジェクトに設定を行うだけで、コードを書かなくてもよいのですが、なぜか4inchと3.5inchのStoryboardの読み分けを行うオプションがないので、didFinishLaunchingWithOptionsにStoryboardを読み分けるコードを記述する必要があります。

と、前提を踏まえた上で、手っ取り早く3.5inch対応のための手順を記載します。

Storyboardの作成
1. NewFile...等で、空のStoryboardを作成(ここでは3_5_inch.storyboardとする)
2. 既存のStoryboard(デフォルトではiPhone.storyboard)を全選択して、コピー。
3. 先ほど作成した空のStoryboardにペースト。
4. Storyboardの右下のアイコンで3.5inch用に切り替える。
http://gyazo.com/8caac61183539ac8b4a845706819d2cd

複雑なレイアウトの場合は修正が必要になるかもしれませんが、大概はこれでOK.

プロジェクトのStoryboardの設定は4inch用のままにしておき、3.5inchのときだけ読みなおすようにします。
サンプルコードは下のようになります。

AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  //3.5inchと4inchを読み分けする
  CGRect rect = [UIScreen mainScreen].bounds;
  if (rect.size.height == 480) {
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"3_5_inch" bundle:nil];
    UIViewController* rootViewController = [storyboard instantiateInitialViewController];

    self.window.rootViewController = rootViewController;
  }

  return YES;
}

基本的には4inchのレイアウトを中心に実装を進めて、3.5inch用Storyboardにコピペ、レイアウト切り替えがスムーズに作業が進みます。

23
23
2

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
23
23