How to line break long large title in iOS 11?
Try this:
for navItem in (self.navigationController?.navigationBar.subviews)! {
for itemSubView in navItem.subviews {
if let largeLabel = itemSubView as? UILabel {
largeLabel.text = self.title
largeLabel.numberOfLines = 0
largeLabel.lineBreakMode = .byWordWrapping
}
}
}
It worked for me.
Navigation Bar black line with Large title
So, after taking a break for the evening, I have found a solution. I am going to leave this post up, for anyone else that might encounter a similar problem in the future.
It is to do with the view of the UINavigationController
itself. I found another stack overflow post that answered it (link here)
All I had to do was:
self.navigationController?.view.backgroundColor = .white
change the colo(u)r to whatever you need it to be.
Simple solution, and I cannot believe it took me so long to figure out.
All the best.
How to turn off adjusting large titles by UITableView in iOS 11?
I've achieved it unintentionally when embedded UITableViewController
inside UIViewController
.
I'm not sure whether it is an Apple's bug or intended behavior.
So stack is as simple as UINavigationController
-> UIViewController
(used as container) -> UITableViewController
Here is sample of view controller with embedded UITableViewController
fullscreen
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var vc = UITableViewController(style: .plain)
var array: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
vc.view.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(vc.view)
view.addConstraint(view.leadingAnchor.constraint(equalTo: vc.view.leadingAnchor))
view.addConstraint(view.rightAnchor.constraint(equalTo: vc.view.rightAnchor))
view.addConstraint(view.safeAreaLayoutGuide.topAnchor.constraint(equalTo: vc.view.topAnchor))
view.addConstraint(view.bottomAnchor.constraint(equalTo: vc.view.bottomAnchor))
vc.tableView.delegate = self
vc.tableView.dataSource = self
array = "0123456789".characters.map(String.init)
vc.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "identifier")
title = "Title"
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath)
cell.textLabel?.text = array[indexPath.row]
return cell
}
}
Here is the result
Hope it helps.
P.S. Surprisingly, my current problem is that I don't know how to get collapsing behavior with such architecture :)
iOS 11 large title navigation bar snaps instead of smooth transition
I faced same issue - I had UIViewController
embedded in UINavigationController
, the UIViewController
had tableview with leading, trailing, top, bottom constraints to safe area. The whole tableview behaved jumpy / snappy. The trick was to change top constraint of tableview to superview.
Here I recorded changing the constraint
tableview iOS 11 bug constraint change
iOS 11 Large Navigation Bar title Objective C?
The property exists; that's just a fact. It's not "working" because you didn't do anything. You can't just sit there and stare at it. If you want this property to be YES, you must set it to YES:
self.navigationController.navigationBar.prefersLargeTitles = YES;
Related Topics
How to Declare Enums in Swift of a Particular Class Type
Checking If a Double Value Is an Integer - Swift
Swift Uialertcontroller with Pickerview Button Action Stay Up
Writing Swift Dictionary to File
Could Not Find an Overload for '/' That Accepts the Supplied Arguments
How to Make Keyboard Dismiss When I Press Out of Searchbar on Swift
Checking If a Value Is Changed Using Kvo in Swift 3
Macos Menubar Application: Main Menu Not Being Displayed
Select Multiple Rows in Tableview and Tick the Selected Ones
How to Run Xctest for a Swift Application from the Command Line
Differencebetween Http Parameters and Http Headers
Invalid Update: Invalid Number of Items in Section 0
How to Rotate Only One View Controller to Landscape Orientation in iOS Swift 3