FacebookSDK(4.1.x) 自定义登录 UI 按钮 - Swift(1.2) [英] FacebookSDK(4.1.x) Custom Login UI Button - Swift(1.2)
问题描述
遵循本教程,我已经设法使 Facebook 登录按钮正常工作.但是,它会从 SDK 自动分配按钮图像,并且无法自定义(因为它不是在 Storyboard 上创建的),因此我无法改用自己的按钮图像或文本.
Following this tutorial, I have managed to make a Facebook Login Button working. However, it is assigning the button image automatically from the SDK and it is not customisable (as it is not getting created on Storyboard), so I am unable to use my own button image or text instead.
我相信这部分代码(在 ViewDidLoad 中)正在分配按钮:
I believe this part of the code (in ViewDidLoad) is assigning the button:
let loginView : FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = self.view.center
loginView.readPermissions = ["public_profile", "email"]
loginView.delegate = self
我需要做的是在 Storyboard 上创建一个 @IBOutlet 按钮并从那里对其进行自定义.我该怎么做?
What I need to do is creating a @IBOutlet Button on Storyboard and customise it from there. How can I do that?
推荐答案
使用自定义按钮和访问令牌登录.
Login with custom button and access token.
在 facebook sdk 4.x 中获取用户信息
Get user info in facebook sdk 4.x
@IBAction func btnFBLoginPressed(sender: AnyObject) {
var fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self, handler: { (result, error) -> Void in
if (error == nil){
var fbloginresult : FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.contains("email"))
{
self.getFBUserData()
fbLoginManager.logOut()
}
}
})
}
func getFBUserData(){
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
println(result)
}
})
}
}
这篇关于FacebookSDK(4.1.x) 自定义登录 UI 按钮 - Swift(1.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!