I want to customize Google Sign-In button like below:-
enter image description here
I have tried below links, but none of them helped really much:- How to customize google sign in button?
https://developers.google.com/identity/sign-in/ios/

有人能指导我该怎么做吗?我不能使用Google+登录按钮,因为"Google+ Sign-In is deprecated".

Edited:- I tried the code provided on below link:-
https://developers.google.com/identity/sign-in/ios/sign-in#add_the_sign-in_button

推荐答案

您可以添加自己的按钮,而不是使用谷歌登录按钮

Objective C Version

1) 将自己的按钮添加到故事板中

2) 将操作拖动到viewController中

- (IBAction)googlePlusButtonTouchUpInside:(id)sender {
     [GIDSignIn sharedInstance].delegate = self;
     [GIDSignIn sharedInstance].uiDelegate = self;
     [[GIDSignIn sharedInstance] signIn];
  }

3) 处理委托方法

#pragma mark - Google SignIn Delegate

- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {

  }

//提供一个提示用户登录谷歌的视图

- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController
{
    [self presentViewController:viewController animated:YES completion:nil];
}

//取消"使用谷歌登录"视图

- (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController {
    [self dismissViewControllerAnimated:YES completion:nil];

}

//已完成登录

- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user
     withError:(NSError *)error {
//user signed in
//get user data in "user" (GIDGoogleUser object)
}

Swift 4 Version

在Swift中,确保你已经添加了briding头,因为库是用objective C编写的

1) 将自己的按钮添加到故事板中

2) 将操作拖动到viewController中

@IBAction func googlePlusButtonTouchUpInside(sender: AnyObject) {
      GIDSignIn.sharedInstance().delegate=self
      GIDSignIn.sharedInstance().uiDelegate=self
      GIDSignIn.sharedInstance().signIn()
} 

3) 处理委托方法

//MARK:Google SignIn Delegate

func signInWillDispatch(_ signIn: GIDSignIn!, error: Error!) {
}

//提供一个提示用户登录谷歌的视图

func signIn(_ signIn: GIDSignIn!,
    presentViewController viewController: UIViewController!) {
  self.present(viewController, animated: true, completion: nil)
}

//取消"使用谷歌登录"视图

func signIn(_ signIn: GIDSignIn!,
    dismissViewController viewController: UIViewController!) {
  self.dismiss(animated: true, completion: nil)
}

//已完成登录

   public func signIn(_ signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
      withError error: Error!) {
        if (error == nil) {
          // Perform any operations on signed in user here.
          let userId = user.userID                  // For client-side use only!
          let idToken = user.authentication.idToken // Safe to send to the server
          let fullName = user.profile.name
          let givenName = user.profile.givenName
          let familyName = user.profile.familyName
          let email = user.profile.email
          // ...
        } else {
          print("\(error.localized)")
        }
    }

编辑:以下是使用自定义按钮Google Doc reference的参考/证据

在这些示例中,视图控制器是

Swift相关问答推荐

自定义完整屏幕封面动画

同步问题,发送Api Call之前未设置idToken

使用SWIFT宏从另一个枚举添加 case

如何访问用户选定目录下的(只读)文件?

在Swift中,是否只有iOS版本超过15才能导入Swift包?

如何让ScrollView缩小到合适的大小,并在没有黑客攻击的情况下占用最小空间

文件命名&NumberForMatter+扩展名&:含义?

关闭 SwiftUI TabView 中的子视图

使用`JSONSerialiser`时,省略通用可选项

如何使一个 Reality Composer 场景中的分组对象可拖动?

如何从 Swift 中隐藏 Objective-C 类接口的一部分?

使用 swift 的 Firebase 身份验证

将每个枚举 case 与 Swift 中的一个类型相关联

如何判断一个值是否为 Int 类型

使用 Async-Await 和 Vapor-Fluent 创建 CRUD 函数 - Swift 5.6

如何有条件地依赖桌面与 iOS 的系统库?

Swift Components.Url 返回错误的 URL

试图同时实现两个混合过渡

是 swift 中另一个日期的同一周、月、年的日期

在 Swiftui 中是否有一种简单的方法可以通过捏合来放大图像?