我对 SwiftUISignInWithAppleButton的signInWithAppleButtonStyle. 我正在尝试根据用户的当前方案或更改按钮的颜色来更改按钮的颜色。这是 iOS 14 和 SwiftUI:
@Environment(\.colorScheme) var currentScheme
@State var appleButtonWhite = false
VStack{
SignInWithAppleButton(
.signUp,
onRequest: { request in
request.requestedScopes = [.fullName, .email]
},
onCompletion: { result in
switch result {
case .success (let authResults):
print("Authorization successful.")
case .failure (let error):
print("Authorization failed: " + error.localizedDescription)
}
}
)
.frame(minWidth: 0, maxWidth: .infinity)
.signInWithAppleButtonStyle(appleButtonWhite ? .white : .black)
}
.onChange(of: currentScheme, perform: { (scheme) in
if scheme == .light
{
appleButtonWhite = false
}
else
{
appleButtonWhite = true
}
})
当appleButtonWhite更改值时,由于状态正在更改,它会按照应有的方式呈现视图。当我调试按钮时,它具有正确的 appleButtonWhite 值,但由于某种原因,样式永远不会改变。我不知道为什么。我在我的代码中使用常规按钮进行了许多样式更改,并且它可以根据不同的状态正常工作。任何想法为什么Apple不会改变?