我以图形方式添加了facebook登录按钮,但是当用户使用不同的语言时,我发现它的高度可变。
这就是它的样子:
我希望能够将facebook登录视图与其他视图之间的距离设置为始终相同,但问题是当您使用英语时,facebook按钮本身的高度小于60(我的情况),但它在其他语言中更大。怎么实现呢?是否可以让按钮本身始终位于视图的底部?或者通过自动布局?不知何故?谢谢你的帮助。
这就是ios模拟器中的样子:
答案 0 :(得分:3)
如果您想坚持使用自己的设计,请使用自定义按钮进行Facebook登录,并在点击按钮时调用以下代码。
@property (strong, nonatomic) IBOutlet UIButton *LoginLogout;
FBSession session;
NSDictionary *permissions;
- (void)updateView {
// get the app delegate, so that we can reference the session property
if (self.session.isOpen) {
// valid account UI is shown whenever the session is open
[self.LoginLogout setText:@"Log out" ];
}
else {
// login-needed account UI is shown whenever the session is closed
[self.LoginLogout setText:@"Login with Facebook" ];
}
}
// handler for button click, logs sessions in or out
- (IBAction)buttonClickHandler:(id)sender {
// get the app delegate so that we can access the session property
// this button's job is to flip-flop the session from open to closed
if (self.session.isOpen) {
// if a user logs out explicitly, we delete any cached token information, and next
// time they run the applicaiton they will be presented with log in UX again; most
// users will simply close the app or switch away, without logging out; this will
// cause the implicit cached-token login to occur on next launch of the application
[self.session closeAndClearTokenInformation];
} else {
if (self.session.state != FBSessionStateCreated) {
// Create a new, logged out session.
self.session = [[FBSession alloc] init];
}
// if the session isn't open, let's open it now and present the login UX to the user
[[self.session initWithPermissions:self.permissions]openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// recurse here, in order to update buttons and labels
[self updateView];
}];
}
}
应在Appdelegate中处理登录响应。所以在Appdelegate.m中包含以下函数
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled =NO;
wasHandled=[FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:self.session];
return wasHandled;
}