LoginSignup
79
60

More than 3 years have passed since last update.

ダークモード適用を回避する方法

Posted at

はじめに

iOS13から遂にダークモードが導入されました。
iOS13 プレビュー記事

今後のiOSアプリ作成にはダークモードを適用が前提となっています。
しかし、アプリ独自のレイアウトを設定しているために、
すぐにはダークモードを適用できない場合があると思います。

そこで今回は、ダークモードを回避する方法を共有します。

UIViewControllerごとに設定

UIViewControllerに追加されたoverrideUserInterfaceStyleの値を指定します。
デフォルトはunspecified(指定なし)です。ユーザーの設定によって変化します。

説明
unspecified 指定なし(デフォルト)
light ライトモード(明るい外観)
dark ダークモード(暗い外観)

UIUserInterfaceStyle - UIKit | Apple Developer Documentation

サンプルコード

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 常にライトモード(明るい外観)を指定することでダークモード適用を回避
        self.overrideUserInterfaceStyle = .light
    }

}

アプリ全体に適用する

アプリ全体に適用するにはInfo.plistUIUserInterfaceStyleパラメータをLightにします。
これで常にライトモードになります。
なおAutomatic(自動)Dark(ダークモード)を指定することもできます。
なお設定しない場合や不正な値が入力された場合は常にLightが採用されます。

まとめ

これらの方法でダークモードの適用を回避することができました。
しかし、Appleはダークモードの適用を推奨しているので、
いずれかのタイミングでアプリにダークモードを適用させる対策が必要です。

この対応はあくまで一時的な対応か外観を変化させたくない特段の事情がある場合に止めるべきでしょう。

参照

Choosing a Specific Interface Style for Your iOS App | Apple Developer Documentation
外観モードの変更方法について

Implementing Dark Mode on iOS - WWDC 2019 - Videos - Apple Developer
WWDC2019のダークモードに関するセッション。動画やサンプルコードがあります。

79
60
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
79
60