[英]SwiftUI SignInWithAppleButton dark mode
我在 SwiftUI 應用程序中使用SignInWithAppleButton 。 但是,當我將設備置於暗模式時,按鈕不會自動更改為人機界面指南建議的暗背景配色方案。 我可以在不手動定義 colors 的情況下啟用該行為嗎?
struct AuthenticationView: View {
var authManager = AuthManager()
var body: some View {
SignInWithAppleButton(
onRequest: { request in
authManager.createRequest(request)
},
onCompletion: { result in
authManager.handleResult(result)
})
.frame(width: 280, height: 45, alignment: .center)
}
}
}
由於某種原因,該按鈕不會使用配色方案自動更新,但您可以使用以下代碼修復它:
struct AuthenticationView: View {
@Environment(\.colorScheme) private var colorScheme
let authManager = AuthManager()
private var buttonStyle: SignInWithAppleButton.Style {
switch colorScheme {
case .light: return .black
case .dark: return .white
@unknown default: return .black
}
}
var body: some View {
SignInWithAppleButton(
.signIn,
onRequest: authManager.createRequest,
onCompletion: authManager.handleResult
)
.signInWithAppleButtonStyle(buttonStyle)
.id(colorScheme)
.frame(height: 56)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.