这个问题非常具体。
有没有办法更改默认的英文标题"使用Facebook登录"对于FBSDKLoginButton类?
在类实现中,我已经看到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");
}
非常感谢任何帮助。
答案 0 :(得分:5)
您可以通过覆盖' setTitle'来扩展FBSDKLoginButton并设置标题。功能(Swift版本):
import Foundation
import FBSDKLoginKit
class MyFBLoginButton: FBSDKLoginButton {
override func setTitle(_ title: String?, for state: UIControlState) {
super.setTitle("YOUR CUSTOM FACEBOOK TITLE", forState: state)
}
}
接下来在故事板中使用您自己的facebook按钮类或按程序添加按钮
答案 1 :(得分: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]);
}
}];
}
答案 2 :(得分:0)
您可以使用这种方法来更改FBSDKLoginButton类的默认英文标题,如下所示:
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"Your custom title"];
[loginButton setAttributedTitle:string forState:UIControlStateNormal];