You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI中SignInWithAppleButton无法适配深色模式如何无需手动定义颜色实现

解决方法

可以实现自动适配,不需要手动定义任何自定义颜色,只需为SignInWithAppleButton指定自动样式即可,该样式会严格跟随系统外观切换符合苹果人机界面指南的配色方案,浅色模式为黑底白字,深色模式为白底黑字,无需额外逻辑。

修改后的代码如下:

struct AuthenticationView: View {
    
    var authManager = AuthManager()
    
    var body: some View {
        SignInWithAppleButton(
            onRequest: { request in
                authManager.createRequest(request)
            },
            onCompletion: { result in
                authManager.handleResult(result)
            })
            .signInWithAppleButtonStyle(.automatic) // 新增这行即可
            .frame(width: 280, height: 45, alignment: .center)
        }
    }
}

补充说明

  • 该样式兼容iOS 14.0+、macOS 11.0+及以上系统版本
  • 除了.automatic外,你也可以根据业务需求手动指定.black/.white/.whiteOutline样式强制固定按钮外观

内容的提问来源于stack exchange,提问作者finn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 10:36:06