I\'m working on App currently and I need to change the default design of Facebook button which is provided by Facebook SDK. I succeeded to let the provided button be transpa
You can use a default UIButton, and use FBSDKManager instead of using Facebook SDK/FBSDKLoginButton to log in. You can set highlighted state color, etc on the UIButton.
Call method fbLoginInitiate from IBAction of your custom FB Button.
func fbLoginInitiate() {
let loginManager = FBSDKLoginManager()
loginManager.logInWithReadPermissions(["public_profile", "email"], handler: {(result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
if (error != nil) {
// Process error
self.removeFbData()
} else if result.isCancelled {
// User Cancellation
self.removeFbData()
} else {
//Success
if result.grantedPermissions.contains("email") && result.grantedPermissions.contains("public_profile") {
//Do work
self.fetchFacebookProfile()
} else {
//Handle error
}
}
})
}
func removeFbData() {
//Remove FB Data
let fbManager = FBSDKLoginManager()
fbManager.logOut()
FBSDKAccessToken.setCurrentAccessToken(nil)
}
func fetchFacebookProfile()
{
if FBSDKAccessToken.currentAccessToken() != nil {
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil) {
//Handle error
} else {
//Handle Profile Photo URL String
let userId = result["id"] as! String
let profilePictureUrl = "https://graph.facebook.com/\(id)/picture?type=large"
let accessToken = FBSDKAccessToken.currentAccessToken().tokenString
let fbUser = ["accessToken": accessToken, "user": result]
}
})
}
}