Hi I want to implement a transcluent NavigationBar so underlying objects are visible.
It should look like here:
This view is a custom view wich uses alpha value to achieve the translucency behavior.
I tried this to implement my custom NavigationBar like this:
UINavigationBar.appearance().barTintColor = .white
UINavigationBar.appearance().tintColor = UIColor(netHex: CxtColor.black.rawValue)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
UINavigationBar.appearance().inputView?.alpha = 0.4
UINavigationBar.appearance().alpha = 0.4
But its not translucent and also the changing of the alpha value has no really effect on the NavigationBar. Its just a white navigationbar.
I don't want to create a full transparent navigationbar.
]you can access navigationBackgroundView
self.navigationController?.navigationBar.isTranslucent = true
let navigationBackgroundView = self.navigationController?.navigationBar.subviews.first
navigationBackgroundView?.alpha = 0.3
Related
I have problem with changing navigation bar color in iOS 15.
In AppDelegate I'm setting UINavigationBarAppearence like this:
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.shadowImage = UIImage()
appearance.shadowColor = .clear
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
In my application, I need to change navigation bar color in multiple places in multiple colors.
Previously, just setting self.navigationController?.navigationBar.barTintColor = .yellow
did the trick but not anymore. Every time when I need to change navigation bar color, do I need to change whole UINavigationBarAppearence class attributes? If yes, it seems like a bit overload. But I cannot find better solution.
Others methods like
self.navigationItem.setHidesBackButton(true, animated: true)
dont work anymore too. Instead
self.navigationController?.navigationBar.topItem?.setHidesBackButton(true, animated: true)
only works. All these change just seems very confusing.
How is it possible to customize the navigation bar like in the AppStore app?
I already tried to set the following (it is a subclass of UINavigationController):
self.navigationBar.setBackgroundImage(UIImage.with(color: UIColor.red), for: .default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.isTranslucent = true
self.view.backgroundColor = .blue
Then the large navigationBar is blue and the small/collapsed navigationBar is red. But what I have to adjust that I get a translucent navigationBar when the navigationBar is collapsed?
[
I need to increase the height of the navigation bar. For this, I have added a view (of desired height) under the navigation bar. The navigation bar is set to be translucent. So the nav bar color is rendered slightly different than the actual hex value. Now I need to match the navigation bar's color to the view below. Following is the code that I am using.
func setupNavigationBar() {
title = "Profile"
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: ""), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage(named: "")
headerView.backgroundColor = navigationController?.navigationBar.barTintColor
headerView.isOpaque = false
}
I am getting different shades as below.
How can i make the view's color to be the same as navigation bar's color? I can get near to the desired color by reducing the view's alpha but I am doubtful about that approach since there is no standard defined regarding it.
P.S. The navigation bar has to stay translucent.
You just need to set opacity of headerView to 0.85
headerView.backgroundColor = navigationController?.navigationBar.barTintColor
headerView.layer.opacity = 0.85
headerView.isOpaque = false
You can download the sample code from here:
Please ignore other unused code in the sample code.
Explanation:
When you're set navigationController style as translucent then the system automatically take layer opacity 0.85 for UINavigationController
I personally check it by iterating all subview of UINavigationController.
Set the background colour to clear for the navigation bar using :
self.navigationController?.navigationBar.backgroundColor = UIColor.clear
Hope this helps.
You can set the background color to nil and it will follow the background color.
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = nil
navigationController?.navigationBar.standardAppearance =
appearance
navigationController?.navigationBar.compactAppearance = appearance
I have a navigation bar created by the nav controller for my view, these are loaded via a container side menu.
When i click an item, it loads the nav controller and view, but the nav bar background drops out showing a blank background colour on the status bar.
Any idea how I can diagnose this issue? I have included some view debugger screenshots to best illustrate
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().barTintColor = UIColor().appThemeColour()
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
UIApplication.shared.statusBarStyle = .lightContent
Well you are missing one thing here and thats setBackgroundImage of UINavigationBar.
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().barTintColor = UIColor().appThemeColour()
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
UIApplication.shared.statusBarStyle = .lightContent
*Note this is the solution for Sidemenu Library named "https://github.com/jonkykong/SideMenu/"
Change status bar end alpha property to 0
Please find code below.
#objcMembers
open class SideMenuPresentationStyle: InitializableClass {
/// Background color behind the views and status bar color
open var backgroundColor: UIColor = .white`
I am just a simple guy struggling to get a translucent navigation bar.
I have tried to set it in appDelegate and in the spesific ViewController.
What i end up with is this:
Does anyone know why the section header in white is moved down? The navigation bar is not even translucent when i scroll and i canĀ“t set a color to it. (i can set color when translucent = false)
I have tried to set it to translucent and opaque and inferred in storyboard.(not working)
Update:
let colorImage = imageFromColor(UIColor(red:0.22, green:0.23, blue:0.29, alpha:0.5), frame: CGRectMake(0, 0, 340, 64))
self.navigationController!.navigationBar.setBackgroundImage(colorImage, forBarMetrics: UIBarMetrics.Default)
self.navigationController!.navigationBar.shadowImage = colorImage
self.navigationController!.navigationBar.translucent = true
The colorImage is a image i make with a rgb-uicolor. The outcome is this: navigation bar 2
It is transclucent between the section header, but the top bar is not!
UPDATE 2
If you are trying to set a translucent background for navigationBar across your application, you can use the following code in application:didFinishLaunchingWithOptions method of your AppDelegate
let colorImage = getImageWithColor(UIColor(red:0.22, green:0.23, blue:0.29, alpha:0.5), size: CGSizeMake(360, 64))
UINavigationBar.appearance().setBackgroundImage(colorImage, forBarMetrics: UIBarMetrics.Default)
UINavigationBar.appearance().translucent = true
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
Result Screenshot: