如何自定义 Google+ 登录按钮

How to customise Google+ Log In button

我在我的应用程序中加入了 FB 和 G+ 注册。

唯一我找不到答案的是如何自定义 GPPSignInButton

我制作了一个常规的 UIButton 并将其 Class 更改为 GPPSignInButton。

结果是这样的:

我不知道这个蓝色区域是什么,也不知道它是怎么到那里的,但我无法通过调用这些方法中的任何一个来改变它

_gButton.backgroundColor = [UIColor redColor];
[_gButton setBackgroundColor:[UIColor redColor]];
[_gButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];

我只需要一个google登录按钮是透明按钮。 如何实现?

我遇到了类似的问题,我是这样解决的:我创建了 gppSignInButton 但没有将其添加为子视图,然后创建了我自己的按钮,使它的视图完全符合我的需要,然后将操作 loginViaGP 添加到我的自己的按钮

- (void)viewDidLoad {
    [super viewDidLoad];
    _gppSignInButton = [[GPPSignInButton alloc] init];
}

- (IBAction)loginViaGP:(id)sender
{
    [_gppSignInButton sendActionsForControlEvents:UIControlEventTouchUpInside];
}

所以在单击我的按钮后调用了 G+ 对话框

您可以拥有自己的 UIButton,通过 IBAction 将其连接到您的 UIViewController 和 运行 自己的身份验证过程,这就是登录按钮的作用幕后花絮:

- (IBAction)signInWithGooglePlusButtonPressed:(UIButton *)sender {
    GPPSignIn *googleSignIn = [GPPSignIn sharedInstance];
    googleSignIn.shouldFetchGooglePlusUser = YES;
    googleSignIn.shouldFetchGoogleUserEmail = YES;
    googleSignIn.clientID = @"CLIENT_ID";
    googleSignIn.scopes = @[ @"profile" ];
    googleSignIn.delegate = self;

    [googleSignIn authenticate];
}

我在 viewDidLoad 中执行了以下操作,效果非常好。

[self.googlePlusBtn setImage:nil forState:UIControlStateNormal];
[self.googlePlusBtn setImage:nil forState:UIControlStateHighlighted];
[self.googlePlusBtn setImage:nil forState:UIControlStateSelected];