ios - 如何让 Facebook 的自定义登录显示在我的 Main.storyboard 上,而不仅仅是在我的代码中

标签 ios swift xcode facebook

我已经成功地将我的自定义 FB 登录实现到我的代码中,并且当我运行模拟器时它会显示/工作,但是,我想在其中实现我的自定义设计。有什么方法可以将它从我的代码中移出并将其显示为 Storyboard 上的按钮以添加所述自定义设计。

这是我已经编写的代码

导入UIKit 导入 Firebase 导入FBSDKLoginKit

类chooseLogInOrSignUpViewController:UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    //add our custom FB log in here

    let customFBButton = UIButton(type: .system)
    customFBButton.backgroundColor = .blue
    customFBButton.frame = CGRect(x: 16, y:50, width: view.frame.width - 32, height: 50)
    customFBButton.setTitle("Connect with Facebook", for: .normal)
    customFBButton.setTitleColor(.white, for: .normal)
    view.addSubview(customFBButton)

    customFBButton.addTarget(self, action: #selector(handleCustomFBLogin), for: .touchUpInside)

}

func handleCustomFBLogin() {
    FBSDKLoginManager().logIn(withReadPermissions: ["email", "public_profile"], from: self)
    { (result,err) in
        if err != nil {
            print("Connect with Facebook failed", err)
            return

        }

        print(result?.token.tokenString)
}

}

  let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "usersVC")

}

最佳答案

你不能。您无法在 Storyboard中查看自定义 View 。 Storyboard 仅渲染出 Apple 实现的某些 UIkit View 。

您可以使用自定义 View 来帮助定位您的 Facebook 登录信息,并使其成为 Facebook 登录信息的子类。但你什么也看不到

关于ios - 如何让 Facebook 的自定义登录显示在我的 Main.storyboard 上,而不仅仅是在我的代码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43191196/

相关文章:

ios - AFNetworking 与不可靠的 wifi - 检测/重试连接超时

ios - Xcode:持久性段错误:使用 Firebase 时为 11

c++ - 如何在 Xcode 中导入 C++ 库?

swift - 如何在 HTTP 请求正文中发送 '&' 字符?

ios - 即使在使用钥匙串(keychain)重新安装应用程序后,为 iOS 设备生成唯一 ID 的正确方法

xcode - Mac 应用程序因使用我未使用的沙盒授权而被拒绝

ios - 在 UISearchController 中隐藏搜索栏上的取消按钮

ios - CAKeyframeAnimation keyTimes设置

ios - 如何更改图标的颜色?

swift - UIImage View 在向后导航时丢失图像