更改FBSDKLoginButton的默认标题

问题描述 投票:1回答:3

问题非常具体。

有没有办法更改FBSDKLoginButton类的默认英文标题“使用Facebook登录”?

在类实现中我已经看到LoginButton.LogInLong是字符串的键,但是我没有运气将键添加到我自己的国际化文件中。此外,我试图在故事板上使用UIButton的title属性,但这不起作用。

我在类的实现文件中发现了这两个方法:

- (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");
}

任何帮助都非常感谢。

ios facebook facebook-ios-sdk
3个回答
5
投票

您可以通过覆盖'setTitle'函数(Swift版本)扩展FBSDKLoginButton并设置title:

import Foundation
import FBSDKLoginKit

class MyFBLoginButton: FBSDKLoginButton {

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

然后在故事板中使用您自己的facebook按钮类或以编程方式添加按钮


0
投票

您可以使用自己的按钮进行Facebook登录,并将下面的代码放入按钮触摸操作中

- (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]);
    }
}];
}

0
投票

您可以使用这种方式更改FBSDKLoginButton类的默认英文标题,如下所示:

FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"Your custom title"];
[loginButton setAttributedTitle:string forState:UIControlStateNormal];
© www.soinside.com 2019 - 2024. All rights reserved.