请帮助
这就是现在发生的事情...自定义图像我需要的是与默认facebook按钮的登录文本重叠,但我不想要在background.it中的默认登录文本也会自动记录-in ..如果我在应用程序中登录
答案 0 :(得分:1)
可能对您有用。
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];
}
}
答案 1 :(得分:0)
自定义脸谱按钮,这是一种非常糟糕的做法,可以通过子视图进行迭代,以试图强制出一些不合意的东西,也就是说,制作自己的按钮并使用下面的方法实现图形API并不难,这些工作,他们提取数据,他们允许您自定义所有内容,他们为您的未来留下了一个非常好的方法,可以在任何应用程序中使用和自定义:
UIButton *_facebookButton = [UIButton buttonWithType:UIButtonTypeCustom];
[[_facebookButton layer] setCornerRadius:2.5];
[_facebookButton setTranslatesAutoresizingMaskIntoConstraints:FALSE];
[_facebookButton setTitle:@"Sign in with Facebook" forState:UIControlStateNormal];
[[_facebookButton titleLabel] setFont:[UIFont systemFontOfSize:15]];
[_facebookButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_facebookButton setBackgroundColor:[UIColor facebookBlue]];
[_facebookButton setTintColor:[UIColor whiteColor]];
[_facebookButton setImageEdgeInsets:UIEdgeInsetsMake(0, -135, 0, -2)];
[_facebookButton setImage:[UIImage imageNamed:@"facebookIconBlue"] forState:UIControlStateNormal];
[[_facebookButton layer] setMasksToBounds:TRUE];
[_facebookButton addTarget:self action:@selector(facebookButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_facebookButton];
处理登录的方法:
-(void)facebookButtonPressed {
if(![FBSDKAccessToken currentAccessToken]) {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error){
if (error) {
//do work
}
else if (result.isCancelled) {
// do work
}
else
{
if ([result.grantedPermissions containsObject:@"email"]) {
[self loadUserData];
}
}
}];
}
else {
[self loadUserData];
}
}
上面的方法然后将自己附加到此方法以从Facebook令牌中提取数据:
- (void)loadUserData {
if([FBSDKAccessToken currentAccessToken]) {
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name"}];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSDictionary *userData = (NSDictionary *)result;
NSString *facebookID = userData[@"id"];
NSString *link = userData[@"link"];
NSString *locale = userData[@"locale"];
NSString *timezone = userData[@"timezone"];
NSString *last_name = userData[@"last_name"];
NSString *email = userData[@"email"];
NSString *gender = userData[@"gender"];
NSString *first_name = userData[@"first_name"];
//**** THIS IS WHERE YOU PUSH YOUR VIEW CONTROLLER, THE USER IS NOW LOGGED IN AND YOU HAVE THE DATA YOU NEED TO RECORD ON YOUR SERVER BACKEND***
}
else if (error) {
}
}];
}
else if (![FBSDKAccessToken currentAccessToken]) {
}
}
请务必记下上面的部分,表明您可以将用户视为“已通过身份验证”的位置。通过子视图迭代到达可以改变的视图是“OKAY”,但这根本不是好习惯。如果不喜欢Facebook登录按钮的外观,最好使用自己的自定义按钮。我希望这会对你有所帮助。