Change the default title of FBSDKLoginButton

一个人想着一个人 提交于 2019-12-11 12:22:50

问题


The question is really specific.

Is there a way to change the default english title "Log in with Facebook" for the FBSDKLoginButton class?

Inside the class implementation I've seen that LoginButton.LogInLong is the key for the string but I had no luck adding the key to my own internationalisation file. Also I've tried to use the title attribute for UIButton on the storyboard but this didn't work.

I've found this two methods inside the implementation file of the class:

- (NSString *)_longLogInTitle
{
  return NSLocalizedStringWithDefaultValue(@"LoginButton.LogInLong", @"FacebookSDK", [FBSDKInternalUtility bundleForStrings],
                                           @"Log in with Facebook",
                                           @"The long label for the FBSDKLoginButton when the user is currently logged out");
}


- (NSString *)_shortLogInTitle
{
  return NSLocalizedStringWithDefaultValue(@"LoginButton.LogIn", @"FacebookSDK", [FBSDKInternalUtility bundleForStrings],
                                           @"Log in",
                                           @"The short label for the FBSDKLoginButton when the user is currently logged out");
}

Any help is really appreciated.


回答1:


You can extend FBSDKLoginButton and set title by override 'setTitle' function (Swift version):

import Foundation
import FBSDKLoginKit

class MyFBLoginButton: FBSDKLoginButton {

    override func setTitle(_ title: String?, for state: UIControlState) {
        super.setTitle("YOUR CUSTOM FACEBOOK TITLE", forState: state)
    }
}

And next use your own facebook button class in storyboard or add button programitically




回答2:


You can use own button for facebook login and put the code below in your button touch-down action

- (IBAction)buttonLoginWithFacebookTapped:(UIButton *)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeClear];
[login logInWithReadPermissions:@[@"email",@"public_profile"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    if (error) {
        NSLog(@"error: %@", [error localizedDescription]);
    } else if (result.isCancelled) {
        NSLog(@"error: Facebook Login Process Cancelled");
    } else {
        NSLog(@"signed auth token - %@ \n %@",result.token,[FBSDKAccessToken currentAccessToken]);
    }
}];
}



回答3:


You can use this way to change the default english title for the FBSDKLoginButton class, as shown below:

FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"Your custom title"];
[loginButton setAttributedTitle:string forState:UIControlStateNormal];


来源:https://stackoverflow.com/questions/33885962/change-the-default-title-of-fbsdkloginbutton

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