我成功地为 web 定制了登录按钮,但我该如何为 iOS 做呢?我一直在寻找,但找不到任何东西。
我目前正在使用 Facebook SDK 3.0,它实现起来相当容易,但 FBLoginView 按钮的设计却显得很突兀。我正在尝试用一个动画按钮来掩盖它,并向前触摸它背后真正的 Facebook 按钮。
Apple 会在提交后拒绝这种变通方法吗?必须有一个更简单的方法,不是吗?
我成功地为 web 定制了登录按钮,但我该如何为 iOS 做呢?我一直在寻找,但找不到任何东西。
我目前正在使用 Facebook SDK 3.0,它实现起来相当容易,但 FBLoginView 按钮的设计却显得很突兀。我正在尝试用一个动画按钮来掩盖它,并向前触摸它背后真正的 Facebook 按钮。
Apple 会在提交后拒绝这种变通方法吗?必须有一个更简单的方法,不是吗?
“如何自定义 FBLoginVIew?”的可能重复项?检查问题和答案
据我所知,目前还没有关于 Facebook 登录视图自定义被拒绝的报告
Yes, you can change it by using below code.
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]];
}
}
请阅读 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";
希望对你有帮助!
//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];
}
}
}];