0
1

More than 1 year has passed since last update.

【SwiftUI】外観モードを固定する

Posted at

はじめに

iPhoneにはライトモードやダークモードに二種類が存在します。
アプリによってはダークモードにさせたくない場合などあると思います。
そんな時に使えるモディファイアを紹介します

ライトモード固定

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
+       .preferredColorScheme(.light)
    }
}

ダークモード固定

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
+       .preferredColorScheme(.dark)
    }
}

おわり

私はこの機能を使用して、アプリ内で外観モードを変更できる機能を提供しています。

0
1
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
0
1