如何更改ios中FBSDKLoginButton的默认loginbutton?

如何在Facebook中自定义loginbutton? 我不想使用Facebook的默认loginbutton。

对于SDK 4.0:

ü应该添加一个button,并在button操作使用下面的代码:

- (IBAction)loginButtonClicked:(id)sender { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Process error NSLog(@"error %@",error); } else if (result.isCancelled) { // Handle cancellations NSLog(@"Cancelled"); } else { if ([result.grantedPermissions containsObject:@"email"]) { // Do work NSLog(@"%@",result); NSLog(@"Correct"); } } }]; } 

更新:接收用户信息

  - (IBAction)loginButtonClicked:(id)sender { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Process error NSLog(@"error %@",error); } else if (result.isCancelled) { // Handle cancellations NSLog(@"Cancelled"); } else { if ([result.grantedPermissions containsObject:@"email"]) { // Do work [self fetchUserInfo]; } } }]; } -(void)fetchUserInfo { if ([FBSDKAccessToken currentAccessToken]) { NSLog(@"Token is available"); [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"Fetched User Information:%@", result); } else { NSLog(@"Error %@",error); } }]; } else { NSLog(@"User is not Logged in"); } } 

你应该添加一个UIButton并添加一个像这样的点击方法:

 - (IBAction)fbLogin:(id)sender { [FBSession.activeSession closeAndClearTokenInformation]; [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"] allowLoginUI:YES completionHandler:^(FBSession *fbSession, FBSessionState state, NSError *error) { [self sessionStateChanged:fbSession state:state error:error]; }]; } 
 FBLoginView *fbLoginView = [[FBLoginView alloc] initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]]; fbLoginView.frame = CGRectMake(0, 200, 271, 37); for (id obj in fbLoginView.subviews) { if ([obj isKindOfClass:[UIButton class]]) { UIButton * loginButton = obj; UIImage *loginImage = [UIImage imageNamed:@"YourImg.png"]; [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal]; [loginButton setBackgroundImage:nil forState:UIControlStateSelected]; [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted]; [loginButton sizeToFit]; } } 

我只是最终在iOS 9.把这个代码放在button操作方法。

 [FBSession openActiveSessionWithReadPermissions:@[@"public_profile",@"email",@"user_friends"] allowLoginUI:YES completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) { // The session is open. Get the user information and update the UI. [FBRequestConnection startWithGraphPath:@"me" parameters:@{@"fields": @"first_name,last_name, email"} HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) { // Set the use full name. NSLog(@"FBresponse: =>%@",result); } else{ NSLog(@"%@", [error localizedDescription]); } }]; }];