Creating your own custom Sign In With Facebook button

suggest change

Sometimes you want your own “Sign In With Facebook” button instead of the button that comes with the Facebook SDK. This sample uses the older FBSDKLoginButton API (readPermissions, sendActionsForControlEvents). The view controller must adopt FBSDKLoginButtonDelegate. Putting this code in the action adds another hidden button on every tap, so create the SDK button once.

  1. In your storyboard, drag out a UIButton and set it up.
  2. Control-drag from that button to the view controller to create an IBAction.
  3. From that action, forward a tap to a hidden Facebook SDK button:

Swift:

let loginButton = FBSDKLoginButton()
loginButton.delegate = self
// Your Custom Permissions Array
loginButton.readPermissions =
[
                         "public_profile",
                         "email",
                         "user_about_me",
                         "user_photos"
]
// Hiding the button
loginButton.hidden = true
self.view.addSubview(loginButton)
// Simulating a tap for the actual Facebook SDK button
loginButton.sendActionsForControlEvents(UIControlEvents.TouchUpInside)

Objective-C:

FBSDKLoginButton *FBButton = [FBSDKLoginButton new];

// Your Custom Permissions Array
FBButton.readPermissions = @[@"public_profile",
                             @"email",
                             @"user_about_me",
                             @"user_photos"
                             ];
FBButton.loginBehavior = FBSDKLoginBehaviorNative;
[FBButton setDelegate:self];
[FBButton setHidden:true];
[self.view addSubview:FBButton];

[FBButton sendActionsForControlEvents:UIControlEventTouchUpInside];

You’re done.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents