ios - Swift Facebook SDK 登录按钮位置

标签 ios swift xcode facebook swift3

我正在使用 Swift 3 和用于登录的 Facebook SDK 开发一个 iOS 应用程序。 我仍然是 iOS 开发的初学者,尤其是关于所有 UI 相关的东西(来自 android 开发)

我正在使用 Facebook SDK 提供的 LoginButton,目前它的位置在屏幕中央。我想将它移到我的 ViewController 的底部,如果可能的话,将它放在我将通过 Storyboard创建的布局中。 (所以它会出现在我想要的地方)

Swift Facebook SDK Login

我查看了 Facebook 开发人员文档,但找不到任何提供 LoginButton 属性以及如何更改其位置的内容。我知道也可以创建自定义 LoginButton,但由于我只想移动按钮而不更改其物理外观,因此我认为没有必要。

let loginButton = LoginButton(readPermissions: [ .publicProfile , .custom("user_birthday")])

loginButton.center = view.center
loginButton.delegate = self

view.addSubview(loginButton)

编辑:

感谢锂的回答,这是我所做的:

let loginButton = LoginButton(readPermissions: [ .publicProfile , .custom("user_birthday")])
let newCenter = CGPoint(x: self.view.frame.width / 2, y: self.view.frame.height - 70)
loginButton.center = newCenter
loginButton.delegate = self
view.addSubview(loginButton)

这将使我的 View Controller 底部的按钮居中,边距为 70。

最佳答案

loginButton.center = view.center

你可以在这里使用任何 CGPoint 而不是 view.center。 例如,

let newCenter = CGPoint(15, 20)
loginButton.center = newCenter

将这个按钮放在屏幕底部的非常懒惰的方法(不使用约束):

let screenSize:CGRect = UIScreen.main.bounds
let screenHeight = screenSize.height //real screen height
//let's suppose we want to have 10 points bottom margin
let newCenterY = screenHeight - loginButton.frame.height - 10
let newCenter = CGPoint(view.center.x, newCenterY)
loginButton.center = newCenter

我现在不能检查这个,但我相信 loginButton.frame 应该也能工作(以及代码中的任何布局限制)。

关于ios - Swift Facebook SDK 登录按钮位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41098733/

相关文章:

ios - UITableViewCell 的 textLabel 中的两行,新行仅由文本中的换行符确定

iphone - iPad 的横向应用程序没有主屏幕横向

ios - 无法在 IOS 11 上启用 http 和 LocalNetwork

ios - 如果文本高度太大,则标签不显示

swift - AVSpeechSynthesiser 窃听 ViewDidLoad 功能

iphone - 在 App Purchase 中不适用于 iPhone 5 设备

ios - cocos2dx - ActionTween 不工作

swift - 如何在不使用 UITextField 的情况下将 UIToolbar 添加到 UIPickerView?

iphone - 如何在 iPhone 应用程序中在推特上发布图片

ios - XCode 和 Facebook IOS SDK - 说明不正确