如何为iOS的FirebaseUIlogin添加背景图片?

我希望能够在FirebaseUIlogin屏幕的三个loginbutton(用于Google,Facebook和电子邮件)后放置背景图像。 FirebaseUIlogin是针对iOS,Android和Web的一种embedded式authentication解决scheme。 我遇到了iOS的麻烦。

Github上有一些build议,但还不够。

我首先初始化我的var customAuthPickerViewController : FIRAuthPickerViewController! 靠近ViewController.swift文件的顶部。

然后,这是我的ViewController.swift文件中的function,但它不工作。 当我点击注销button,应用程序崩溃,并没有显示任何背景图像。

 // Customize the sign-in screen to have the Bizzy Books icon/background image func authPickerViewController(for authUI: FIRAuthUI) -> FIRAuthPickerViewController { customAuthPickerViewController = authPickerViewController(for: authUI) backgroundImage = UIImageView(image: UIImage(named: "bizzybooksbee")) backgroundImage.contentMode = UIViewContentMode.scaleAspectFill customAuthPickerViewController.view.addSubview(backgroundImage) return customAuthPickerViewController } 

背景图像“bizzybooksbee”是一个通用图像集,1x,2x和3x图像已经加载到我的Assets.xcassets文件夹中。

这里是一个没有尝试实现背景图像的login屏幕的样子 。

在这里输入图像说明

更新:我能够让图像显示,与我在下面的评论中给出的代码,但它显示在loginbutton,如下图所示。

在这里输入图像说明

这是Jeffrey的帮助下的“平等”的图像:

在这里输入图像说明

这是解决scheme!

  1. 从ViewController.swift中移除不起作用的垃圾:

     func authPickerViewController(for authUI: FIRAuthUI) -> FIRAuthPickerViewController { customAuthPickerViewController = authPickerViewController(for: authUI) backgroundImage = UIImageView(image: UIImage(named: "bizzybooksbee")) backgroundImage.contentMode = UIViewContentMode.scaleAspectFill customAuthPickerViewController.view.addSubview(backgroundImage) return customAuthPickerViewController } 
  2. 创build一个FIRAuthPickerViewController的.swift“子类”,你可以命名任何东西,并在那里添加你的背景图片/定制:

    // BizzyAuthViewController.swift // Bizzy Books // // Created by Brad Caldwell on 10/11/16. // Copyright © 2016 Caldwell Contracting LLC. All rights reserved. //

    import UIKit

    import FirebaseAuthUI

    class BizzyAuthViewController: FIRAuthPickerViewController {

     override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let width = UIScreen.main.bounds.size.width let height = UIScreen.main.bounds.size.height let imageViewBackground = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height)) imageViewBackground.image = UIImage(named: "bizzybooksbee") // you can change the content mode: imageViewBackground.contentMode = UIViewContentMode.scaleAspectFill view.insertSubview(imageViewBackground, at: 0) }} 
  3. 在你的ViewController.swift(或者你所说的任何东西)中,在你login的部分,将authViewController改为等于你的新子类,为导航控制器添加一行,并把它传递给self.present:

    let authViewController = BizzyAuthViewController(authUI: authUI!)

    let navc = UINavigationController(rootViewController: authViewController)

    self.present(navc, animated: true, completion: nil)

我也做了一个YouTube教程 ,展示了如何深入这一点。