2016-10-02 98 views
0

我已將Facebook登錄按鈕添加到我的應用程序,但是當我無法將其從左上角移動到屏幕中心時。 我想:無法更改FBSDKLoginButton位置

loginButton.center = (self.view?.center)! 

loginButton.frame = CGRect(origin: CGPoint(x: self.frame.midX,y :self.frame.midY), size: CGSize(width: loginButton.frame.width, height: loginButton.frame.height)) 

但既不工作,中心變量的變化,但按鈕依然在左上角

有誰知道如何解決這一問題?

我這個代碼

let loginButton: FBSDKLoginButton = { 
     let button = FBSDKLoginButton() 
     button.readPermissions = ["email"] 
     button.translatesAutoresizingMaskIntoConstraints = false 
    return button 
    }() 
view.addSubview(loginButton) 
+0

你如何添加按鈕來查看?請分享您用來添加按鈕的代碼行。 – DevKyle

+0

讓loginButton:FBSDKLoginButton = { 令按鈕= FBSDKLoginButton() button.readPermissions = [ 「電子郵件」] button.translatesAutoresizingMaskIntoConstraints =假 返回按鈕 }() view.addSubview(loginButton) – toiavalle

回答

1

添加按鈕,你應該設置你這樣的代碼:

let loginButton = FBSDKLoginButton(frame: CGRect(x: 0, y: 0, width: //whatever width you want, height: //whatever height you want)) 
    loginButton.readPermissions = ["email"] 
    loginButton.center = view.center 
    view.addSubview(loginButton) 

參考https://developers.facebook.com/docs/facebook-login/ios#loginkit