Subtitle Above Large Nav Bar Title - ios

I was wondering how we could get the subtitle (like a date) above the navbar title when using the prefersLargeTitles feature. Something like the music app. I would also like the large button beside it (like the profile button in the music app). I would still like the large title to animate to the top and become small when the screen is scrolled (like the browse page on the music app).
The code I am using so far is
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.prefersLargeTitles = true
collectionView.initialize()
self.title = "Home Screen"
}

Related

UISheetPresentationController displaying differently on different phones

I created a UIStoryboardSegue to make a "Bottom Sheet segue". Our designer shared a screenshot of the app on his phone and the bottom sheet is displaying differently, despite the fact we are both on the same iOS version.
On mine and my simulator, when the bottom sheet opens, it lightens the source view and then shrinks it down a little, so it appears just barely behind the bottom sheet
On the same screen on the designers device, it dims the background and leaves the source view full size, showing the top of the buttons in the navigation bar
I've noticed the Apple maps bottom sheet behaves like the designers, no shrinking of the background view. But I can't see any settings that would affect this. How can I stop the sheet from resizing the source view on mine and function like it's supposed to?
Here's my code:
import UIKit
public class BottomSheetLargeSegue: UIStoryboardSegue {
override public func perform() {
guard let dest = destination.presentationController as? UISheetPresentationController else {
return
}
dest.detents = [.large()]
dest.prefersGrabberVisible = true
dest.preferredCornerRadius = 30
source.present(destination, animated: true)
}
}
Found a hack to force it to never minimise the source view at least, not really what I wanted, but keeps it consistent. Supposedly, .large() is always supposed to minimize the source view, you can avoid this in iOS 16 by creating a custom detent that is just a tiny bit smaller than large like so:
let customId = UISheetPresentationController.Detent.Identifier("large-minus-background-effect")
let customDetent = UISheetPresentationController.Detent.custom(identifier: customId) { context in
return context.maximumDetentValue - 0.1
}
dest.detents = [customDetent]
And as a bonus, found a way to control the dimming on the bottom sheet overlay. There is a containerView property on the presentationController, but it is nil when trying to access it in while in the segue. If you force code to run on the main thread, after the call to present, you can access the containerView and set your own color / color animation
e.g.
...
...
source.present(destination, animated: true)
DispatchQueue.main.async {
dest.containerView?.backgroundColor = .white
}

Change UINavigationItem accessibility elements order

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. 👍

How to create a search bar with mic icon in iOS 13?

In iOS 13, search bars in all Apple apps have a mic icon on the right that allows for voice input. However, when I create a system search bar (or UISearchController), I don't get the mic icon. I've searched on Google and SO and couldn't find the answer - is it something we can adopt, and if so how?
One important note is that currently there is not a way to programmatically put the user into "Dictation mode". This means to implement this, your must use the Speech framework in order to get "speech-to-text" working from a button press.
You can accomplish the visual styling by updating the image for the search bar's bookmark icon and setting showsBookmarkButton on the search bar to true.
Here is an implementation with a UISearchController:
let searchController = UISearchController(searchResultsController: nil)
let micImage = UIImage(systemName: "mic.fill")
searchController.searchBar.setImage(micImage, for: .bookmark, state: .normal)
searchController.searchBar.showsBookmarkButton = true
You handle the button tap via the search bar's delegate:
searchController.searchBar.delegate = self
func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) {
// Do work here
}

Prevent UISearchBarController to show UINavigationBar

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
}

How do you make a dropdown searchbar?

In the iOS calendar app, when you press the search icon, an animated dropdown containing a search bar is shown, and it instantly gains focus.
Before Pressing The Search Icon
After Pressing The Search Icon
How would I go about developing a similar search dropdown in my onw app? What sort of classes / methods would I use to achieve this and how would they be put together? Note, I'm sure I could find a third party library to handle this, but I want to know how the could be done using only core iOS libraries.
lazy var searchBar = UISearchBar(frame: CGRectMake(0, 0, 0, 0))
override func viewDidLoad() {
super.viewDidLoad()
searchBar.placeholder = "Search"
self.navigationItem.rightBarButtonItem.image = UIImage(named: searchIcon.png)
}
func searchIconTapped() {
navigationItem.titleView = searchBar
}
To go back to default, just set the navigationItem.titleView back to nil

Resources