How to customize FBLoginVIew?

后端 未结 17 847
暗喜
暗喜 2020-12-02 05:56

In order to connect to facebook in my ios app i\'m using FBLoginVIew from Facebook SDK for iOS.

It shows a nice FB Login Button, but I want to use my own image and t

相关标签:
17条回答
  • 2020-12-02 06:47

    change text in the Facebook resource bundle en.lproj Localizable.strings ... i suppose it works

    0 讨论(0)
  • 2020-12-02 06:50

    When I'm writing this, Facebook has already released version 3.0 of their SDK for iOS.

    ozba's answer is sort of working but, from my opinion, it shouldn't be used.

    • Firstly, and most important, it's a general rule that it's bad practice to iterate through the subviews/superviews of an SDK component because the hierarchy can change between the SDK versions, causing errors that will be hard to track and, then, repair.
    • Secondly, when the button is clicked, for a second or two, it comes back to the original text.

    My solution is really simple. In Facebook's downloaded folder, FacebookSDK, you have a folder named Samples. There, you must look in the SessionLoginSample. You can see that they have an ordinary Round Rect Button, which, through the ViewController that owns it, that has the FBLoginViewDelegate, it can change text depending on the FBSession state. Trust me, it's really simple.

    0 讨论(0)
  • 2020-12-02 06:50

    According to latest Facebook Login For iOS Version 2.3.

    You can use the following code snippet to login via any any Custom UIButton.

    - (void)loginWithFacebook:(id) sender {
       FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
       [login logInWithReadPermissions:@[@"public_profile",@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // Process error
        } else if (result.isCancelled) {
            // Handle cancellations
        } else {
            // Login Successful here
    
            // Check for any particular permissions you asked
            if ([result.grantedPermissions containsObject:@"email"]) {
                // Do work
            }
         }
      }];
    }
    

    Here is the link: https://developers.facebook.com/docs/facebook-login/ios/v2.3#login-apicalls

    0 讨论(0)
  • 2020-12-02 06:51

    Please, read the README file in Facebook SDK. You have to add the Row - FacebookBundleName in info.plist and put it a name for your bundle. Then, add a bundle to your project with this name and put into folders named "lang.lproj": for example: en.lproj - it.lproj - fr.lproj - es.lproj.... Into this folders you have to add the Localizable.strings file, then you can localize a lot of phrases, like:

    "FBLV:LogOutButton" = "Log Out";
    "FBLV:LogInButton" = "Log In";
    "FBLV:LoggedInAs" = "Logged in as: %@";
    "FBLV:LoggedInUsingFacebook" = "Logged in using Facebook";
    "FBLV:LogOutAction" = "Log Out";
    "FBLV:CancelAction" = "Cancel";
    

    Hope it helps you!

    0 讨论(0)
  • 2020-12-02 06:52

    Since the latest version 4.X Facebook SDK ,

    The Custom Login is made easier, Use FBSDKLoginManager

    0 讨论(0)
  • 2020-12-02 06:55

    In My case I created a good looking Button in Photoshop and simply put it on top of faceBook button. (I know that Apple doesn't advice to put view on button But iterating on the subviews doesn't look nice to me). Hard to understand why such company as FB didn't provide simple way to do it.

    UIImageView *fbImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"facebookButton.png"]];
    CGRect newFrame = fBButtonFrame;
    newFrame.origin.x = 0; newFrame.origin.y = 0;
    [fbImageView setFrame:newFrame];
    [fbImageView setUserInteractionEnabled:NO];
    
    FBLoginView *loginView = [[FBLoginView alloc] init];
    [loginView setFrame:fBButtonFrame];
    [loginView addSubview:fbImageView];
    [self.view addSubview:loginView];
    
    0 讨论(0)
提交回复
热议问题