如何为iOS的FirebaseUI登录添加背景图像?

时间:2022-03-20 06:56:14

I'd like to be able to place a background image behind the three sign-in buttons (for Google, Facebook, and Email) of the FirebaseUI login screen. FirebaseUI login is a drop-in authentication solution for iOS, Android, and Web. I'm having trouble with iOS.

我希望能够在FirebaseUI登录屏幕的三个登录按钮(用于Google,Facebook和电子邮件)后面放置背景图像。 FirebaseUI登录是iOS,Android和Web的嵌入式身份验证解决方案。我在使用iOS时遇到了麻烦。

There's a little bit of advice on Github, but not enough.

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

I first initialize my var customAuthPickerViewController : FIRAuthPickerViewController! near the top of the ViewController.swift file.

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

Then, this is the function in my ViewController.swift file, but it's not working. When I click the logout button, the app crashes, and no background image is ever shown.

然后,这是我的ViewController.swift文件中的函数,但它不起作用。当我单击注销按钮时,应用程序崩溃,并且没有显示任何背景图像。

// 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
}

The background image "bizzybooksbee" is a Universal Image Set with 1x, 2x, and 3x images already loaded in my Assets.xcassets folder.

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

Here's a picture of what the login screen looks like without trying to implement the background image.

这是一张没有尝试实现背景图像的登录屏幕的图片。

如何为iOS的FirebaseUI登录添加背景图像?

UPDATE: I'm able to get the image to show, with the code I gave in the comments below, but it shows OVER the sign-in buttons, as in the pic below.

更新:我可以使用我在下面的评论中给出的代码来显示图像,但它显示了登录按钮,如下图所示。

如何为iOS的FirebaseUI登录添加背景图像?

Here's an image of the "heirarchy," with Jeffrey's help:

这是杰里瑞的帮助下的“heirarchy”的图像:

如何为iOS的FirebaseUI登录添加背景图像?

1 个解决方案

#1


3  

Here's the solution!

这是解决方案!

Remove the junk that doesn't work from ViewController.swift:

从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   
}

Create a .swift "subclass" of FIRAuthPickerViewController that you can name anything, and add your background image/customization there:

创建一个FIRAuthPickerViewController的.swift“子类”,你可以命名任何东西,并在那里添加你的背景图像/自定义:

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)
    }}

In your ViewController.swift (or whatever you call it), in the section where you login, change authViewController to equal your new subclass, add a line for the navigation controller, and pass it into the self.present:

在您的ViewController.swift(或其他任何名称)中,在您登录的部分中,将authViewController更改为等于您的新子类,为导航控制器添加一行,并将其传递给self.present:

let authViewController = BizzyAuthViewController(authUI: authUI!)

let navc = UINavigationController(rootViewController: authViewController)

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

I also made a YouTube tutorial which shows how to do this in depth.

我还制作了一个YouTube教程,展示了如何深入地完成这项工作。

#1


3  

Here's the solution!

这是解决方案!

Remove the junk that doesn't work from ViewController.swift:

从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   
}

Create a .swift "subclass" of FIRAuthPickerViewController that you can name anything, and add your background image/customization there:

创建一个FIRAuthPickerViewController的.swift“子类”,你可以命名任何东西,并在那里添加你的背景图像/自定义:

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)
    }}

In your ViewController.swift (or whatever you call it), in the section where you login, change authViewController to equal your new subclass, add a line for the navigation controller, and pass it into the self.present:

在您的ViewController.swift(或其他任何名称)中,在您登录的部分中,将authViewController更改为等于您的新子类,为导航控制器添加一行,并将其传递给self.present:

let authViewController = BizzyAuthViewController(authUI: authUI!)

let navc = UINavigationController(rootViewController: authViewController)

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

I also made a YouTube tutorial which shows how to do this in depth.

我还制作了一个YouTube教程,展示了如何深入地完成这项工作。