I am trying to show a large Title
in a Navigation bar
, but with clear background. When scrolled up, it will be the Navigation bar
with a blur effect.
This looks correct, however, when scrolling, the animation seems to be broken. Also, transition gets stuck from time to time:
My code as follows:
UINavigationController
:
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 13.0, *) {
self.navigationBar.prefersLargeTitles = true
let style = UINavigationBarAppearance()
style.configureWithDefaultBackground()
style.titleTextAttributes = [.font: UIFont.systemFont(ofSize: 18)]
self.navigationBar.standardAppearance = style
self.navigationBar.compactAppearance = style
//Configure Large Style
let largeStyle = UINavigationBarAppearance()
largeStyle.configureWithTransparentBackground()
largeStyle.largeTitleTextAttributes = [.font: UIFont.systemFont(ofSize: 28)]
self.navigationBar.scrollEdgeAppearance = largeStyle
}
}
The UITableView
is inside the UINavigationController
. Both are from storyboards via a segue way.
Instead of UITableview, You can try using UITableViewController. I have tried using UITableViewController and its working fine for me. Please check the following design and code.
class ViewController: UITableViewController
{
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 13.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
let style = UINavigationBarAppearance()
style.configureWithDefaultBackground()
style.titleTextAttributes = [.font: UIFont.systemFont(ofSize: 18)]
self.navigationController?.navigationBar.standardAppearance = style
self.navigationController?.navigationBar.compactAppearance = style
//Configure Large Style
let largeStyle = UINavigationBarAppearance()
largeStyle.configureWithTransparentBackground()
largeStyle.largeTitleTextAttributes = [.font: UIFont.systemFont(ofSize: 28)]
self.navigationController?.navigationBar.scrollEdgeAppearance = largeStyle
}
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
// Do any additional setup after loading the view.
}
override func numberOfSections(in tableView: UITableView) -> Int {
1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
10
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = "\(indexPath.row)"
return cell
}
}
Output:-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With