Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Add a Background Image for FirebaseUI Login for iOS?

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.

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

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

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.

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

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

enter image description here

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.

enter image description here

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

enter image description here

like image 778
Brad Caldwell Avatar asked Oct 07 '16 15:10

Brad Caldwell


People also ask

How do I add a background image to my backendless app?

When selecting a background image, you can either enter an image URL from the web, or you can choose an image from the File Storage of your Backendless app. Clicking the three-dot button next to the image URL accesses your File Storage where you can choose or upload an image. Customize how your background image appears and responds to user actions.

Can I add a background image to the UI builder components?

Background images aren’t just for pages. Several of the UI Builder components can have their own background image. In fact, for the Container component, you can include a background image on the Container, on individual rows, or even on each individual cell.

How do I add a background image to my website?

To add a background image, you simply have to select the page or component and open the Background menu item.

What is the purpose of background images?

Remember, the purpose of background images is to add visual style to your app. These are typically images that the user will not directly interact with.


1 Answers

Here's the solution!

Remove the junk that doesn't work from 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:

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:

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.

like image 58
Brad Caldwell Avatar answered Sep 19 '22 12:09

Brad Caldwell