I gave my tableViewController a large title Style programmatically:
self.navigationController?.navigationBar.prefersLargeTitles = true
and in storyboard, I made tableView "Static Cell" content, and "Grouped" Style in Attributes inspector:
But largeTitle didn't work when I ran the app, if tableView style is "Plain", it works. How can I fix it?
I'm not sure if it's your case, but for me using tableView.bounces = false prevented the large-title from working. Removing this line did the trick.
Where did you put your self.navigationController?.navigationBar.prefersLargeTitles = true. I putted it in ViewDidload and it's works properly
It's not clear to me why this occurs. Quite possibly a bug. But here is a work around. In Document Outline. Select your Navigation Controller Scene -> Navigation Bar then select Prefer Large Titles (at the top) in Attribute Inspector like so:
After making this change, if you want other view controllers to have regular / plain titles, simply add this to viewDidLoad() on that particular V.C.
navigationItem.largeTitleDisplayMode = .never
Remove title from your storyboard
In your UIViewController over viewDidLoad function:
navigationItem.title = "Search title"
navigationController?.navigationBar.prefersLargeTitles = true
Related
I have a UINavigationBar which contains 3 parts:
titleView (which is UISearchBar)
leftBarButtonItems
rightBarButtonItems
when the voice-over is on, the search bar will be the first one to be focused.
which is not confirmed to the left to right order we are familiar with.
I tried to set UINavigationItem's accessibilityElements, but it still will highlight the searchBar first. assume because, inside the UINavigationItem, the titleView is the first subView.
any ideas on how to change the order, thanks~
Any ideas on how to change the order?
I assume your problem deals with the way you added the search bar in the navigation bar.
I created a blank project as follows:
The code snippet hereafter is an example of adding a search bar as the title view: 🤓
class SearchViewController: UIViewController, UISearchBarDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let search = UISearchBar()
search.showsCancelButton = true
search.delegate = self
self.navigationItem.titleView = search
}
}
The result with VoiceOver on gives rise to the following screenshots:
Following this rationale, you have the VoiceOver initial reading order from left to right in the navigation bar. 🥳🎊🎉
I suggest to take a look at this site if further information is needed about a11y in the navigation bar and especially if you want to make a specific reading order. 👍
I have a table view in navigation controller so that I can push the detail view controller on the stack. It works fine, until I add a search controller to the navigation item, like so:
searchController = UISearchController(searchResultsController: nil)
searchController.obscuresBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.delegate = self
searchController.searchBar.tintColor = Colors.mlLabel
navigationItem.searchController = searchController
definesPresentationContext = true
It results in temporary grey background, see below:
When debugging the view hierarchy, it looks like UIViewControllerWrapperView's _UIParallaxDimmingView(selected below) is causing this, as both navigation bar and status bar are transparent.
How can I fix this?
Note: Setting the animated property in pushViewController() to false works, but I'd like to keep the animation.
Update: This seems to be issue only on iOS 13. Probably from some recent version even, as I didn't have this issue earlier.
Update 2: I've noticed the same issue on multiple places in my app now, and it's not just in combination with SearchController. Basically the _UIParallaxDimmingView sticks its nose out.
Update
Here's the code I use to go from a large title to a small title. These are properties for the large title viewcontroller, or more specific its navigation controller:
navigationController.navigationBar.prefersLargeTitles = true
navigationController.topViewController?.extendedLayoutIncludesOpaqueBars = true
Perhaps the second line above might help you?
As for pushing any view controllers, I see I've overridden the push-function from the navigation controller (as I use the navigation controller for each tab in my tabbar):
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if viewControllers.count >= 1 {
viewController.hidesBottomBarWhenPushed = true
viewController.navigationItem.largeTitleDisplayMode = .never
}
super.pushViewController(viewController, animated: animated)
}
Previous answer
I saw this a couple of times before in my life and it always had to do something with the background color of the view controller itself. If it's transparent you see this stuff when animating.
But since it's a search controller, it might be the navigation bar. Anyway, since the issue is only since iOS13, I believe the issue can be resolved using this:
searchController.searchBar.backgroundColor = UIColor.clear (or whatever color)
This new property (UISearchBar.searchTextField.backgroundColor) has been added since iOS13, so maybe this will solve it for you? :)
I've finally found a solution. One of the problems was that I've set a background color for the navbar like so:
UINavigationBar.appearance().backgroundColor = .white
So removing the above line and adding the below line to the view controller being pushed fixed it.
extendedLayoutIncludesOpaqueBars = true
I'm using MvxTabBarViewController that is attributed with:
[MvxFromStoryboard("Main")]
[MvxRootPresentation(WrapInNavigationController = true)]
It does not present "More" button when I have more than five tabs added to the controller. Instead only the first four are shown.
The tabs are MvxViewControllers that are attributed with:
[MvxFromStoryboard("Main")]
[MvxTabPresentation(WrapInNavigationController = false, TabIconName = "icon", TabName = "Tab 1")]
They are presented from ViewWillAppear(bool animated) method using NavigationService.Navigate(TabOneViewModel)
I tried setting WrapInNavigationController to false, but still no luck.
Any help would be appreciated.
When using a Storyboard, in order to add a TabBarController to your application you need to drag and drop a UITabBarViewController instead of a plain UIViewController. Otherwise some properties are not correctly derived (like the TabBar in this case - please see my screenshot).
Just make sure you delete the automatically created TabBar items!
So I have a basic view controller with a navigation bar, this is view controller B, so I'm performing a segue to go here, and I'm trying to change the title like this:
override func viewDidLoad() {
debugPrint(self.selectedName)
super.viewDidLoad();
self.navigationItem.title = "A NEW TITLE"
}
But it doesn't do anything
To set Title on NavigationBar simply we can do by below code
self.title = "Your Title"
For Swift 3:
If you want to set just the navigation title without using a UINavigationController then make an outlet of the navigation item as
#IBOutlet weak var navItem: UINavigationItem!
and then in viewDidLoad() write
navItem.title = "ANY TITLE"
There are plenty of methods which you can follow to achieve this. Here is few of those.
First things first.
If you are ready to "Embed in" a navigation controller or if you have already one then you can access that using following code.
self.navigationController?.navigationBar.topItem?.title = "Your Title"
Now for more customization:
Place a UINavigationBar object on ViewController scene and add constraints to it.
Make an outlet of newly placed UINavigationBar like as follows -
#IBOutlet weak var orderStatusNavigationbar: UINavigationBar!
Now set the title using the outlet.
orderStatusNavigationbar.topItem?.title = "Your Title"
All this above code are in Swift 3 but will work on lower versions of Swift also(atleast on Swift 2.0)
Hope this helped.
Swift 4 / XCode 10
Add new NavigationBar -> Drap and Drop it to your view
Press CTRL to add new Outlet Action
Example : #IBOutlet weak var main_navbar: UINavigationBar in ViewController class.
Then set the title : main_navbar.topItem?.title = "YOUR TITLE"
This solution worked for me, hope it does for you too.
- rust
Ok,
So you need to embed the whole thing in a Navigation Controller first, and then make that navigation controller as the initial controller.
Select your storyboard, click the first controller then click this -
Then you remove the navigation bar you set(put) over the last controller named "title".
The reason this didnt work, as you are trying to change the title of the navigation controller's navigation bar, but it doesnt have it, hence it cant change it.
I'm using a UINavigationBar ALWAYS hidden (I'm using NavigationBar facilities to push ou pop views but I'm not showing it to final user), the problem is that in one of those views I have a tableView with UISearchBar. When I select the searchBar, make a search and click on it's "Cancel" button the NavigationBar appears, but I want to keep the Navigation hidden as it is.
I've tried to hidden the navigationBar one more time by willDismissSearchController or didDismissSearchController by
func willDismissSearchController(searchController: UISearchController) {
self.navigationController?.navigationBar.hidden = true
}
but it did not worked as I want.
Thank you in advance.
I've found a solution, so as it is a unusual question I'll reply for other people know the solution.
the following code did worked for me:
override func viewDidLayoutSubviews() {
self.navigationController?.navigationBar.hidden = true
}