将应用程序切换到黑暗模式时,confirmationDialog
显示为白色。如何使confirmationDialog
也在黑暗模式下显示?
import SwiftUI
struct SettingListView: View, Themeable {
@Environment(\.dismiss) var dismiss
@State private var showingConfirmation = false
@Environment(\.colorScheme) var colorScheme
@AppStorage("isDarkMode") private var isDarkMode = false
@StateObject var settingsListViewModel = SettingsListViewModel()
@State private var changeValueID = true
@State private var showContacts = true
var body: some View {
NavigationStack {
List {
Section {
VStack {
ZStack(alignment: .bottomTrailing) {
Image("avatar")
.resizable()
.scaledToFill()
.frame(width: 120, height: 120)
.clipShape(Circle())
.onTapGesture {
showingConfirmation = true
}
.confirmationDialog("Change Profile Picture", isPresented: $showingConfirmation, titleVisibility: .visible) {
Button(role: .none, action: {}) {
Text("Take Photo")
}
Button(role: .none, action: {}) {
Text("Choose from library")
}
Button(role: .none, action: {}) {
Text("Use Avatar")
}
}
Image(systemName: "pencil")
.foregroundColor(isDarkMode ? .white : .black)
.frame(width: 28, height: 28)
.background(isDarkMode ? Color(#colorLiteral(red: 0.370555222, green: 0.3705646992, blue: 0.3705595732, alpha: 1)) : Color(#colorLiteral(red: 0.921431005, green: 0.9214526415, blue: 0.9214410186, alpha: 1)))
.clipShape(Circle())
.overlay {
Circle().stroke(isDarkMode ? .black : Color(.secondarySystemBackground), lineWidth: 4)
}
.scaleEffect(x: 1.1, y: 1.1, anchor: .center)
}
}
字符串
3条答案
按热度按时间00jrzges1#
您可能需要添加.preferredColorScheme()
字符串
差不多吧可能需要玩修改器在哪里。我从来没有使用过它,所以我不完全确定它会去哪里。
zfycwa2u2#
字符串
这是可行的,但它会使整个
.confirmationDialog
的颜色相同。ewm0tg9j3#
您正确阅读colorScheme:
第一个月
但你却不用它代替变量
isDarkMode
,在颜色修改器中使用colorScheme == .dark
,使视图适应配色方案。在您的示例中:
字符串
不阅读环境值
colorScheme
的一个更简单的选项是将颜色选择留给具有语义颜色的系统:型
在这种情况下省略.background(Color...)