gpt4 book ai didi

ios - 如何为 iOS 的 FirebaseUI 登录添加背景图片?

转载 作者:搜寻专家 更新时间:2023-10-31 22:12:50 29 4
gpt4 key购买 nike

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

关于Github有一点建议, 但还不够。

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

然后,这是我的 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
}

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

这是 a picture of what the login screen looks like无需尝试实现背景图像。

enter image description here

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

enter image description here

在 Jeffrey 的帮助下,这是一张“等级制度”的图片:

enter image description here

最佳答案

这是解决方案!

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

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

在你的 ViewController.swift(或者你怎么调用它)中,在你登录的部分,将 authViewController 更改为等于你的新子类,为导航 Controller 添加一行,并将其传递给 self 呈现:

let authViewController = BizzyAuthViewController(authUI: authUI!)

let navc = UINavigationController(rootViewController: authViewController)

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

我还做了一个YouTube tutorial其中展示了如何深入执行此操作。

关于ios - 如何为 iOS 的 FirebaseUI 登录添加背景图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39920485/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com