How to Line Break Long Large Title in iOS 11

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.

Sample Image

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

Sample Image

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



Leave a reply



Submit