问题
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.
回答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.
回答2:
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
回答3:
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.
回答4:
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.
回答5:
- Open storyboard as source code.
- Locate the button in the xml.
- Set customClass="GIDSignInButton" as an attribute for the button tag.
- Open storyboard as interface builder.
You can now link the button to the IBOutlet
回答6:
I had the same problem a few months ago,
Your code seems to be right
@IBOutlet weak var signInButton: GIDSignInButton!
But, the problem might be
• You haven’t added the Framework properly (Go to your project setting in the left side navigator, and click Build phases, add your framework and SHIFT + CMD + K)
• Or alternatively, go ahead and write the @IBOutlet in your swift file, then drag the button to assign it
• your last option is to close xcode, or maybe delete the derived data
Xcode itself has plenty of bugs, I am not sure if it’s your problem, it’s xcode’s
Hope this helps!
回答7:
If you use a UIView instead of a UIButton, you can assign the view a custom class of GIDSignInButton. From there you can connect the view to a button outlet and action as seen below.
@IBOutlet weak var googleLoginButton: GIDSignInButton!
@IBAction func googleLoginButtonPressed(_ sender: Any) {
GIDSignIn.sharedInstance()?.signIn()
}
回答8:
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
回答9:
Swift- 5
Open storyboard as source code.
Locate the button in the xml.
Set customClass="GIDSignInButton" as an attribute for the button tag.
Open storyboard as interface builder.
//MARK:- You will not find this with button XML Forcly Add this (customClass="GIDSignInButton")[![enter image description here][1]][1]
回答10:
The simple way to do is just make a button action and paste the following lines in it.
@IBAction func gSignInAction(_ sender: Any) {
GIDSignIn.sharedInstance()?.signIn()
}
来源:https://stackoverflow.com/questions/47960149/cant-change-custom-class-of-uibutton-to-gidsigninbutton