程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在 SwiftUI 中设置 Apple SSO 按钮尺寸大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决在 SwiftUI 中设置 Apple SSO 按钮尺寸?

开发过程中遇到在 SwiftUI 中设置 Apple SSO 按钮尺寸的问题如何解决?下面主要结合日常开发的经验,给出你关于在 SwiftUI 中设置 Apple SSO 按钮尺寸的解决方法建议,希望对你解决在 SwiftUI 中设置 Apple SSO 按钮尺寸有所启发或帮助;

我不知道如何让这个苹果登录按钮变得更宽更高。无论我在哪里尝试添加 .frame(wIDth: .... 它似乎只是在屏幕上移动按钮。但是,不会改变按钮本身的尺寸。

这是在 ContentVIEw.swift 中:

struct ContentVIEw : VIEw {
      @State var credentials: CredentialsOrError?
      var body: some VIEw {
        vstack {
          if $credentials.wrappedValue == nil {
            SignInWithApplebutton(credentials: $credentials)
          }
          else if $credentials.wrappedValue!.issuccess
          {
            Text("User: \($credentials.wrappedValue!.values!.user)")
            Text("Given name: \($credentials.wrappedValue!.values?.givenname ?? "")")
            Text("Family name: \($credentials.wrappedValue!.values?.familyname ?? "")")
            Text("Email: \($credentials.wrappedValue!.values?.email  ?? "")")
          }
          else {
            Text($credentials.wrappedValue!.error!.localizedDescription).foregroundcolor(.red)
          }
        }.fullScreenCover(isPresented: .constant($credentials.wrappedValue != nil && $credentials.wrappedValue!.issuccess),content: {
            HomeVIEw()
        })
      }
}

来自SignInWithApplebutton.swift

struct SignInWithApplebutton: VIEw {
  
  @Binding var credentials: CredentialsOrError?
    
  var body: some VIEw {
    
    let button = buttonController(credentials: $credentials)
                                    
    return button
        .frame(wIDth: button.button.frame.wIDth,height: button.button.frame.height,alignment: .center)
  }
  
  struct buttonController: UIVIEwControllerRepresentable {
    let button: ASAuthorizationApplEIDbutton = ASAuthorizationApplEIDbutton()
    let vc: UIVIEwController = UIVIEwController()
    
    @Binding var credentials: CredentialsOrError?

    func makeCoordinator() -> Coordinator {
      return Coordinator(self)
    }
    
    func makeUIVIEwController(context: Context) -> UIVIEwController {
      vc.vIEw.addSubvIEw(button)
      return vc
    }
    
    func updateUIVIEwController(_ uiVIEwController: UIVIEwController,context: Context) { }
    
    class Coordinator: NSObject,ASAuthorizationControllerDelegate,ASAuthorizationControllerPresentationContextProvIDing {
      let parent: buttonController
      
      init(_ parent: buttonController) {
        self.parent = parent
        
        super.init()
        
        parent.button.addTarget(self,action: #SELEctor(dIDTapbutton),for: .touchUpInsIDE)
      }
      
      @objc func dIDTapbutton() {
        let applEIDProvIDer = ASAuthorizationApplEIDProvIDer()
        let request = applEIDProvIDer.createrequest()
        request.requestedScopes = [.fullname,.email]
        
        let authorizationController = ASAuthorizationController(authorizationrequests: [request])
        authorizationController.presentationContextProvIDer = self
        authorizationController.delegate = self
        authorizationController.performrequests()
      }
      
      func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
        return parent.vc.vIEw.window!
      }
      
      func authorizationController(controller: ASAuthorizationController,dIDCompleteWithAuthorization authorization: ASAuthorization) {
        guard let credentials = authorization.credential as? ASAuthorizationApplEIDCredential else {
          parent.credentials = .error("Credentials are not of type ASAuthorizationApplEIDCredential")
          return
        }
        
        parent.credentials = .credentials(user: credentialS.User,givenname: credentials.fullname?.givenname,familyname: credentials.fullname?.familyname,email: credentials.email)
      }
      
      func authorizationController(controller: ASAuthorizationController,dIDCompleteWithError error: Error) {
        parent.credentials = .error(error)

      }
    }
  }

}

附上一张我目前在暗模式 iPhone 上的样子的图片,我还附上了一张亮模式模拟器的图片。

相关问题:如何将屏幕背景硬编码为白色?

在模拟器中:

在 SwiftUI 中设置 Apple SSO 按钮尺寸

在我的深色模式 iPhone 上:

在 SwiftUI 中设置 Apple SSO 按钮尺寸

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的在 SwiftUI 中设置 Apple SSO 按钮尺寸全部内容,希望文章能够帮你解决在 SwiftUI 中设置 Apple SSO 按钮尺寸所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。