Trying to use a navbar not in a nav controller?
Picture of my extended navbar hack (set to blue for visibility)
After creating my messages navbar with this:
let navBar = UINavigationBar(frame: CGRect(x: 0, y: 44.0, width: UIScreen.main.bounds.width, height: 55.0))
self.view.addSubview(navBar)
navBar.items?.append(UINavigationItem(title: "title"))
if #available(iOS 13.0, *) {
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.backgroundColor = UIColor.white
navBar.standardAppearance = navBarAppearance
navBar.scrollEdgeAppearance = navBarAppearance
} else {
//ConvoViewController.edgesForExtendedLayout = []
}
I would encounter the issue where the user could scroll up and see messages above the navbar overlayed with the time/battery/wifi signal making for very poor UI.
To solve this, I created a UITextView to subview just as I had the navbar, I set the background to blue so you can see it but you can change it to any color.
let navBar = UINavigationBar(frame: CGRect(x: 0, y: 44.0, width: UIScreen.main.bounds.width, height: 55.0))
var textView = UITextView(frame: CGRect(x: 0, y: 0.0, width: UIScreen.main.bounds.width, height: 55.0))
textView.backgroundColor = UIColor.blue
self.view.addSubview(textView)
self.view.addSubview(navBar)
navBar.items?.append(UINavigationItem(title: "title"))
if #available(iOS 13.0, *) {
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.backgroundColor = UIColor.white
navBar.standardAppearance = navBarAppearance
navBar.scrollEdgeAppearance = navBarAppearance
} else {
//ConvoViewController.edgesForExtendedLayout = []
}