gpt4 book ai didi

以编程方式快速设置 LoginButton 的约束

转载 作者:行者123 更新时间:2023-11-30 10:49:24 26 4
gpt4 key购买 nike

我想将 Facebook 身份验证的登录按钮设置到 View 底部。我尝试了这个,但它不起作用:

let lb = LoginButton(readPermissions: [ .email, .publicProfile ])
lb.center = view.bottomAnchor

不知道如何将其水平设置到 View 中心底部

最佳答案

 let lb = UIButton()//LoginButton(readPermissions: [ .email, .publicProfile ])
lb.center = self.view.center

//设置约束

  NSLayoutConstraint.activate([
lb.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), // centerXAnchor which set over the view center
lb.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor, constant: 70.0), // BottomAnchor to set with botton target
lb.widthAnchor.constraint(equalToConstant: 170.0), // Width Anchor to set appropriate width
lb.heightAnchor.constraint(equalToConstant: 44.0) // Height Anchor to set appropriate hegiht of the button.
])

self.view.addSubview(lb)
lb.delegate = self

如果编程约束有任何问题,您甚至可以从 UI 界面(Storyboard 或 XIB)添加该按钮。

简单地,使用@IBOutlet 创建一个实例。分配 FBSDKLoginButton 类并将委托(delegate)设置为该按钮。

@IBOutlet weak var loginButton: FBSDKLoginButton!

欲了解更多信息,请访问此链接:Facebook Login button for Swift

关于以编程方式快速设置 LoginButton 的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54984377/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com