目前在我的应用程序中,图像我在这个ContentView.swift文件look fine on an iPhone with its display settings set to Dark mode(第一个图像)然而,当我使用我的模拟器时,这是set to light mode, it doesn't have good contrast(第二个图像).

暗模式图像(好,我希望两者看起来像):

dark mode images (good)

光模式图像(由于对比度低和易读性差):

light mode images (bad)

struct ContentView: View {
    @StateObject var sharedVars = SharedVarsBetweenTabs()
    
    var body: some View {
        TabView {
            HomeView().environmentObject(sharedVars)
                .tabItem {
                    Text("Home")
                    Image(systemName: "house.fill")
                }
            AppearanceView().environmentObject(sharedVars)
                .tabItem {
                    Text("Appearance")
                    Image(systemName: "paintbrush.fill")
                  }
            QuotesView().environmentObject(sharedVars)
                .tabItem {
                    Text("Quotes")
                    Image(systemName: "quote.bubble.fill")
                }
        }
        .environmentObject(sharedVars)
        .accentColor(.blue)
    }
        
}

理想情况下,I simply want them to both look like the dark mode image, regardless of what the user's phone display setting is—因为应用程序的背景是相同的.我将非常感谢任何帮助或建议.

推荐答案

您可以很容易地强制图标独立于环境.o(v)o><

其中加上:

.onAppear {
  UITabBar.appearance().unselectedItemTintColor = UIColor.white
}

show

显示图像代码:

import SwiftUI

struct ContentView: View {
  
  var body: some View {
    
    TabView {
      Text("Hi")
        .tabItem {
          Text("Home")
          Image(systemName: "house.fill")
        }
      Text("Hi")
        .tabItem {
          Text("Appearance")
          Image(systemName: "paintbrush.fill")
        }
      Text("Hi")
        .tabItem {
          Text("Quotes")
          Image(systemName: "quote.bubble.fill")
        }
    }
    .accentColor(.blue)
    .onAppear {
      //Backgroud Color
      UITabBar.appearance().backgroundColor = UIColor(Color(red: 79/255, green: 65/255, blue: 54/255))
      
      //Icon Color
      UITabBar.appearance().unselectedItemTintColor = UIColor(Color(red: 133/255, green: 123/255, blue: 116/255))
    }
    .environment(\.colorScheme, .light)
  }
}

#Preview {
  ContentView()
}

Ios相关问答推荐

使用音频单元播放音频流,出现爆裂声

Xcode15.3上的生成错误:调用的对象类型';facebook::flipper::SocketCertificateProvider';不是函数或函数指针

在iOS中禁用URLSession自动重试机制

以编程方式更改VC&39;S导航栏按钮的属性,以响应另一个VC中的按钮按下

使用AVCaptureEventInteraction捕获音量按键快门

Swift - 缺少函数参数在编译期间不会失败,甚至会导致不同的数据类型?

Swift Vision库识别文本后如何将其赋值给 struct 体实例属性以供显示?

@MainActor 类的扩展是主要演员吗?

Swift如何表示单位转换的标准大气压

UIButton在iOS7中没有显示突出显示

iOS:应用程序在安装应用程序时未征求用户许可.每次都获得 kCLAuthorizationStatusNotDetermined - Objective-c & Swift

iOS swift从另一个数组中删除一个数组的元素

在 iPhone 中将 UIViewController 显示为弹出窗口

从 WKWebView 获取所有 cookie

SwiftUI NavigationView navigationBarTitle LayoutConstraints 问题

iPhone 未连接.连接 iPhone 后 Xcode 将继续

为什么 Xcode 4 不创建任何产品?

比较没有时间分量的 NSDates

在 NSUserDefaults 中存储值是否有任何限制?

openURL:在 iOS 10 中已弃用