はじめに
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)
}
}
おわり
私はこの機能を使用して、アプリ内で外観モードを変更できる機能を提供しています。