In my application I am using below code to add default navigation.
self.navigationController?.navigationBar.barStyle = UIBarStyle.default
self.navigationController?.navigationBar.backgroundColor = UIColor.clear
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.barTintColor = // my color
self.navigationController?.navigationBar.tintColor = // my color
self.navigationController?.navigationBar.shadowImage = UIImage()
This code works fine till iOS 10. But in iOS 11 the back icon is not in the center.
I checked other similar issues regarding view title here and here but couldn't find any solution. Thanks.
So I found this answer and I did the same.
Removing this line from AppDelegate works for me.
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment (UIOffsetMake(0, -60), for: .default)
Related
I want to show you the results of the screenshot that I have face issues with it.
but I can see the setting has like that.
I have tried this code to make the background clear for iOS 13 and above.
let app = UINavigationBarAppearance()
let navigationBar = self.navigationController?.navigationBar
app.backgroundColor = .clear
app.configureWithOpaqueBackground()
app.configureWithOpaqueBackground()
app.titleTextAttributes = [.foregroundColor: UIColor.white]
app.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
app.backgroundColor = .clear
self.navigationController?.navigationBar.scrollEdgeAppearance = app
navigationBar!.standardAppearance = app
navigationBar!.scrollEdgeAppearance = app
so it does not work as well. How can I make the Navigation bar visible the UIImage that built-in UITableView?
What about add blur background in iOS 14? I can't find it.
Let me know thanks!
I'm applying the new appearance API for NavigationBar and I'm struggling with the status bar content (text). On Info.plist I forced to use the light mode because most of the app is white, but in one of my viewControllers, the navigation bar is dark blue (almost black) so the content within this bar needs to be white.
I used to use navigationBar.barStyle = .black on versions up to iOS 12.4, but for iOS 13 and above it doesn't work anymore. Follow the code I've tried and failed.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let navController = self.navigationController {
let navBarAppearance = navController.navigationBar.standardAppearance.copy()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.shadowImage = UIImage()
navBarAppearance.backgroundColor = LayoutBootstrap.colors.primary.solid // Dark blue
navController.navigationBar.standardAppearance = navBarAppearance
navController.navigationBar.barStyle = .black
}
}
Status bar content is black
PS: On didFinishLaunchingWithOptions I already called a default configuration appearance for NavigationBar and Items
Do you guys have any suggestion?
Thanks in advance.
You need to set the status bar style as well
UIApplication.shared.statusBarStyle = .lightContent
I`m preparing app for iOS 13, and get bug with search controller in navigation bar. How to solve navigation bar glitch?
let search = UISearchController(searchResultsController: nil)
search.dimsBackgroundDuringPresentation = false
search.searchResultsUpdater = self
search.hidesNavigationBarDuringPresentation = false
self.definesPresentationContext = true
search.searchBar.isTranslucent = false
self.navigationItem.searchController = search
self.navigationItem.hidesSearchBarWhenScrolling = true
Press Cancel and navigation bar items becomes untouchable.
Pushing view controller leads to navigation bar item overlap.
I have created test project on git https://github.com/eKroman/TESTsearchBar
Bug appears on iOS 13 beta (tested on iPad) using from Xcode 11 from beta 7 (maybe older beta) to Xcode 11 GM seed 2.
Does not appear on simulators.
I encountered the same problem, if I cancel the searchBar and change the navigationItem.title then I have a double title 👍. It's like a ghost layer of the navigation bar stays here in the navigation controller.
This is how I fixed it:
searchController.hidesNavigationBarDuringPresentation = true
Probably best to use it until Apple fix this issue.
I also noticed that the back button switch to default color (blue), as if the navigationBar TintColor was reset.
Config:
- Xcode 11.0 (11A420a)
- iOS 13.1 (17A5844a)
For the back button reset to default color (blue) in #CoachThys's answer, I manage to work around it by the code below.
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
/* .. set other things on appearances */
appearance.buttonAppearance.normal.titleTextAttributes = [.foregroundColor: color]
standardAppearance = appearance
compactAppearance = appearance
scrollEdgeAppearance = appearance
}
However, I cannot find a way to work around the back indicator image which is still reset to blue color briefly.
Add custom backbutton with a image would fixed the new bug. It works well for me.
let negativeSpacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
negativeSpacer.width = -8
self.navigationItem.leftBarButtonItems = [negativeSpacer, leftBarButtonItem]
How can I implement this code in swift 4 or xcode 9?
// Remove hairline between navigation bar and anything below such as search bar
UINavigationBar.appearance().shadowImage = UIImage()
I want to remove navBar underline.
Don't worry copy pasting will work.
// Remove Bottom Shadow
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
Please check :
self.navigationController?.navigationBar.shadowImage = UIImage()
So I've been desperately trying hide the navigationBar bottom border/shadow. I've gone through all the SO answers I can get, but nothing works right.
Setting navBar background and shadow image to empty uiimage does nothing:
navigationController?.navigationBar.setBackgroundImage(UIImage(named: ""), forBarPosition: UIBarPosition.Any, barMetrics: UIBarMetrics.Default)
navigationController?.navigationBar.shadowImage = UIImage(named: "")
Setting clipsToBounds or masksToBounds = true works, but I lose status bar on top and when push to next VC with same navController, I get a black status bar.
navigationController?.navigationBar.layer.masksToBounds = true
or
navigationController?.navigationBar.clipsToBounds = true
Setting in appDelegate also does not work:
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "")
UINavigationBar.appearance().shadowImage = UIImage(named: "")
I'm using Swift on iOS 8. Thanks for any other suggestions!
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)