Question or problem with Swift language programming:
I’m trying to add Google sign in functionality to a custom button, and I’m following this tutorial. It’s telling me to select the button, and set its class as GIDSignInButton, then add this code: @IBOutlet weak var signInButton: GIDSignInButton!.
However, it doesn’t let me set the class to GIDSignInButton. When I type it in and press enter, the field just clears.
How to solve the problem:
Solution 1:
The workaround is open the storyboard
in text mode and put it directly. When you return to the interface builder
it will show normally.
Solution 2:
You should try assign GIDSignInButton not to the Button Object from the Object library but to the the View Object instead
It’s work for me.
It will look like this using UIView instead of UIButton.
Solution 3:
That’s because GIDSignInButton is a subclass of UIView, not UIButton.
Add to the storyboard / nib a regular UIView and change it’s class to GIDSignInButton instead.
From google doc:
Add a GIDSignInButton to your storyboard, XIB file, or instantiate it
programmatically. To add the button to your storyboard or XIB file,
add a View and set its custom class to GIDSignInButton.
Solution 4:
You can create UIButton and then on its action method you can write this code for signing via google:
GIDSignIn.sharedInstance().signIn()
It works for me, in this way you can customize UIButton according to your requirement and also perform signin by using google
Solution 5:
GIDSignInButton can be set by using a UIView
or a UIButton
.
If you are using GIDSignInButton
as a UIButton
- open the storyboard as source code
- Find the button in resulting
XML
-
Add the below code as an attribute for the button tag
customClass="GIDSignInButton"
4.open storyboard
again as Interface Builder, button class will be changed
If you are using GIDSignInButton as a UIView
1.copy paste the custom class as GIDSignInButton
in Identity Inspector
The second one is the correct approach in my opinion.