How to change title of Google Plus Sign in button?

旧时模样 提交于 2019-12-12 10:44:20

问题


I was searching for solution but to my suprise nobody asked this question yet:

How to change title of Google Sign In button?

I was trying to:

  1. override title by setTitle: but didn't help.
  2. find "Sign in" string in Google Plus framework directory but well... my Finder didn't find such string. 3.Use following code which works for changing Facebook Login button:

    for (id obj in self.signInButtonGPP.subviews)
    {
         if ([obj isKindOfClass:[UILabel class]])
         {  UILabel * label =  view;
            label.text = @"Google";
         }}
    

Thank you


回答1:


The resources for the button are contained in the GooglePlus.bundle file. The value for the label is coming from the GooglePlusPlatform.strings file in the bundle.

You can directly edit the value of the Sign in key to have a custom title. (This would be a dirty fix though, you must do it for all the locales.)

And while doing that be sure to comply with the Google+ Sign-In button branding guidelines.




回答2:


Well.. I think you can use same solution I used when it came to change Facebook login button text. Maybe its not the best & clean way, but.. it works. All you need to do is to set your original G+ login button frame to CGRectZero, and than add your own button with the same look as G+ button has, and custom text. Than, when you detect touch on your button you need to pass it to G+ button like this:

[self.gppSigninButton sendActionsForControlEvents:UIControlEventTouchUpInside];

Didn't test it, but i think it'll work fine. Hope it'll help you.




回答3:


I'm assuming you're using the custom GPPSigninButton class that Google provides.

In this sample project, looks like the "Sign In" text is part of an image, so unfortunately you cannot change this text. You will have to create a button and handle the sign-in event yourself with an IBAction.

I have created my own sample app using the latest version of the SDK. Looking at the button through the View Debugger, it does have a label, but it is not exposed in the header file.

//
//  GPPSignInButton.h
//  Google+ iOS SDK
//
//  Copyright 2012 Google Inc.
//
//  Use of this SDK is subject to the Google+ Platform Terms of Service:
//  https://developers.google.com/+/terms
//

#import <UIKit/UIKit.h>

// The various layout styles supported by the GPPSignInButton.
// The minmum size of the button depends on the language used for text.
// The following dimensions (in points) fit for all languages:
// kGPPSignInButtonStyleStandard: 226 x 48
// kGPPSignInButtonStyleWide:     308 x 48
// kGPPSignInButtonStyleIconOnly:  46 x 48 (no text, fixed size)
typedef enum {
  kGPPSignInButtonStyleStandard = 0,
  kGPPSignInButtonStyleWide = 1,
  kGPPSignInButtonStyleIconOnly = 2
} GPPSignInButtonStyle;

// The various color schemes supported by the GPPSignInButton.
typedef enum {
  kGPPSignInButtonColorSchemeDark = 0,
  kGPPSignInButtonColorSchemeLight = 1
} GPPSignInButtonColorScheme;

// This class provides the Google+ sign-in button. You can instantiate this
// class programmatically or from a NIB file.  You should set up the
// |GPPSignIn| shared instance with your client ID and any additional scopes,
// implement the delegate methods for |GPPSignIn|, and add this button to your
// view hierarchy.
@interface GPPSignInButton : UIButton

// The layout style for the sign-in button. The default style is standard.
@property(nonatomic, assign) GPPSignInButtonStyle style;

// The color scheme for the sign-in. The default scheme is dark.
@property(nonatomic, assign) GPPSignInButtonColorScheme colorScheme;

@end

Unfortunately this means you cannot change this text.




回答4:


The Google Plus SDK doesn't provide you any Settings Bundle along with it's SDK.

Settings Bundle is something that has all the images used inside it.

Google Plus library has**.a** extension means you don't have any access to it's files.

Plus, the Sign In button is an image, so you won't be able to change it's title.

Try subclassing the GPPSignInButton and change it's image / title as per your need in awakeFromNib method.

Hope this helps..



来源:https://stackoverflow.com/questions/27783735/how-to-change-title-of-google-plus-sign-in-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!