Firebase AuthUI iOS自定义

时间:2018-08-26 01:29:32

标签: firebase firebase-authentication firebaseui

我正在尝试自定义iOS上默认Firebase AuthUI屏幕的配色方案。我可以更改NavigationBar文本颜色,但是不能更改左LeftNavigationBarItem文本属性或主视图背景颜色。

这是我用来更改NavigationBar上主要文本属性的代码:

let authVC = authUI!.authViewController()
authVC.navigationBar.barTintColor = UIColor.black
authVC.navigationBar.barStyle = .blackTranslucent
authVC.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor (displayP3Red: 255/255, green: 212/255, blue: 121/255, alpha: 1.0)]

我已经尝试过以下代码(一次一行)来更改NavigationBarItem文本属性:

authVC.navigationBar.backItem?.backBarButtonItem?.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor (displayP3Red: 255/255, green: 212/255, blue:121/255, alpha: 1.0) ], for: .normal)
authVC.navigationItem.backBarButtonItem?.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor (displayP3Red: 255/255, green: 212/255, blue: 121/255, alpha: 1.0) ], for: .normal)

我已经尝试过更改视图背景属性,一次又更改一行:

authVC.visibleViewController?.view.backgroundColor = UIColor.black 
authVC.view.backgroundColor = UIColor.black  
authVC.view.layer.backgroundColor = UIColor.black.cgColor
authVC.visibleViewController?.view.layer.backgroundColor = UIColor.black.cgColor

我正在使用FirebaseUI(5.2.0),FirebaseAuth(5.0.3)和Xcode 9.4.1。

任何指针都会受到赞赏。

谢谢

2 个答案:

答案 0 :(得分:1)

通过对FUIAuthPickerViewController进行子类化并在viewDidLoad方法中设置view.backgroundColor进行排序

答案 1 :(得分:0)

下面的代码是如何更改scoobydoo所指出的背景颜色的,在像这样添加自定义控制器作为根之后,我也能够修改authViewController

让authViewController = MyAuthPickerViewController(authUI:authUI)

nav = UINavigationController(rootViewController:authViewController)

import UIKit
import FirebaseUI

class MyAuthPickerViewController : FUIAuthPickerViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let scrollView = view.subviews[0]
        scrollView.backgroundColor = .clear
        let contentView = scrollView.subviews[0]
        contentView.backgroundColor = .clear

        let width = UIScreen.main.bounds.size.width
        let height = UIScreen.main.bounds.size.height

        let backgroundImage = UIImageView(frame: CGRect(x: 0, y: -1, width: width, height: height))

        backgroundImage.image = UIImage(named: "switchStarback")
        backgroundImage.alpha = 0.6
        view.backgroundColor = UIColor.init(named: "MatteBlack")

        backgroundImage.contentMode = UIView.ContentMode.scaleAspectFill

        view.insertSubview(backgroundImage, at: 0)
    }

}