我的应用程序有 Facebook 登录按钮,但我无法将它从左上角移到屏幕中央。 我试过:
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))
但都不起作用,center 变量改变了,但按钮仍然在左上角
有人知道如何解决这个问题吗?
我正在用这段代码添加按钮
let loginButton: FBSDKLoginButton = {
let button = FBSDKLoginButton()
button.readPermissions = ["email"]
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()
view.addSubview(loginButton)
最佳答案
你应该这样设置你的代码:
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
关于swift - 无法更改 FBSDKLoginButton 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39813099/