自定义移动 Facebook 登录按钮?
Posted
技术标签:
【中文标题】自定义移动 Facebook 登录按钮?【英文标题】:Customize the mobile Facebook login button? 【发布时间】:2012-09-13 16:49:49 【问题描述】:我成功地为网页定制了登录按钮,但我该如何为 ios 做呢?我一直在寻找,但没有找到任何东西。
我目前使用的是 Facebook SDK 3.0,它实现起来相当容易,但 FBLoginView 按钮的设计让人大跌眼镜。我正在尝试用一个动画按钮来掩盖它,并向前触摸它背后真正的 Facebook 按钮。
Apple 会在提交后拒绝这种解决方法吗? 一定有更简单的方法,不是吗?
【问题讨论】:
【参考方案1】:Possible Duplicate of "How to customize FBLoginVIew?" check both Question & Answer
据我所知,没有报告拒绝自定义 Facebook 登录视图的问题
【讨论】:
我猜这确实是重复的,它几乎完全相同并且有效!我应该将搜索重点放在 FBLoginView 上,我可能会找到我的答案。谢谢!【参考方案2】:是的,您可以使用以下代码进行更改。
for (id obj in loginview.subviews)
if ([obj isKindOfClass:[UIButton class]])
UIButton * loginButton = obj;
[loginButton setBackgroundColor:[UIColor blueColor]];
UIImage *loginImage = [UIImage imageNamed:@"facebook_btn~ipad.png"];
[loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
[loginButton setBackgroundImage:nil forState:UIControlStateSelected];
[loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
[loginButton sizeToFit];
if ([obj isKindOfClass:[UILabel class]])
UILabel * loginLabel = obj;
loginLabel.text = @"Login with facebook";
loginLabel.textAlignment = NSTextAlignmentCenter;
loginLabel.frame = CGRectMake(0, 30, 600, 30);
//loginLabel.text. = [UIFont fontWithName:@"Default" size:30.0];
[loginLabel setFont:[UIFont boldSystemFontOfSize:27]];
【讨论】:
【参考方案3】:请阅读 Facebook SDK 中的 README 文件。 您必须在 info.plist 中添加 Row - FacebookBundleName 并将其命名为您的捆绑包。 然后,使用此名称将包添加到您的项目中,并放入名为“lang.lproj”的文件夹中: 例如:en.lproj - it.lproj - fr.lproj - es.lproj.... 在这个文件夹中你必须添加 Localizable.strings 文件,然后你可以本地化很多短语,比如:
"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";
希望对你有帮助!
【讨论】:
【参考方案4】://Add the normal button then add your own image and tittle and give the action the button and use the below code in the button action.
NSMutableDictionary *fbResultData;
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile", @"email", @"user_friends"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
if (error)
NSLog(@"Process error");
else if (result.isCancelled)
NSLog(@"Cancelled");
else
NSLog(@"Logged in");
if ([FBSDKAccessToken currentAccessToken])
[[[FBSDKGraphRequest alloc] initWithGraphpath:@"me?fields=id,name,age_range,birthday,devices,email,gender,last_name,family,friends,location,picture" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
if (!error)
NSString * accessToken = [[FBSDKAccessToken currentAccessToken] tokenString];
NSLog(@"fetched user:%@ ,%@", result,accessToken);
fbResultData =[[NSMutableDictionary alloc]init];
if ([result objectForKey:@"email"])
[fbResultData setObject:[result objectForKey:@"email"] forKey:@"email"];
if ([result objectForKey:@"gender"])
[fbResultData setObject:[result objectForKey:@"gender"] forKey:@"gender"];
if ([result objectForKey:@"name"])
NSArray *arrName;
arrName=[[result objectForKey:@"name"] componentsSeparatedByString:@" "];
[fbResultData setObject:[arrName objectAtIndex:0] forKey:@"name"];
if ([result objectForKey:@"last_name"])
[fbResultData setObject:[result objectForKey:@"last_name"] forKey:@"last_name"];
if ([result objectForKey:@"id"])
[fbResultData setObject:[result objectForKey:@"id"] forKey:@"id"];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:@"me/picture?type=large&redirect=false"]
parameters:nil
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error)
if (!error)
if ([[result objectForKey:@"data"] objectForKey:@"url"])
[fbResultData setObject:[[result objectForKey:@"data"] objectForKey:@"url"] forKey:@"picture"];
//You get all detail here in fbResultData
NSLog(@"Final data of FB login********%@",fbResultData);
self.fullNameTextField.text = [fbResultData objectForKey:@"name"];
self.lastNameTextField.text = [fbResultData objectForKey:@"last_name"];
[_customFaceBookButton setImage:[UIImage imageNamed:@"fb_connected"] forState:UIControlStateNormal];
];
else
NSLog(@"result: %@",[error description]);
AlertView *alert = [[AlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:[error description] delegate:nil cancelButtonTitle:NSLocalizedString(@"DISMISS", nil) otherButtonTitle:nil];
[alert showInView:self.view.window];
];
else
[[FBSDKLoginManager new] logOut];
[_customFaceBookButton setImage:[UIImage imageNamed:@"fb_connected"] forState:UIControlStateNormal];
];
【讨论】:
希望对大家有所帮助 添加普通按钮,然后将您自己的图像和标题添加到您的按钮,并将操作赋予按钮并在按钮操作中使用以下代码以上是关于自定义移动 Facebook 登录按钮?的主要内容,如果未能解决你的问题,请参考以下文章
自定义 Google Plus 登录按钮和 Facebook 登录按钮