Masta
Masta

Reputation: 521

Use large navigation title and fit text

I have issue with navigation bar title. First of all I am using large titles with:

navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always

Is it possible to have a large title with resizable fonts?

enter image description here

Upvotes: 2

Views: 2473

Answers (2)

Shubham Daramwar
Shubham Daramwar

Reputation: 287

There is one property called largeTitleTextAttributes. I think it will solve your problem. Write the following code in view controller's viewDidLoad method.

    self.navigationItem.largeTitleDisplayMode = .always
    self.navigationController?.navigationBar.prefersLargeTitles = true
    self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 100)]

Upvotes: 4

sazid008
sazid008

Reputation: 185

You have to resize your title view. Try this

    self.title = "Your TiTle Text"
    let tlabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
    tlabel.text = self.title
    tlabel.textColor = UIColor.white
    tlabel.font = UIFont(name: "Helvetica-Bold", size: 30.0)
    tlabel.backgroundColor = UIColor.clear
    tlabel.adjustsFontSizeToFitWidth = true
    tlabel.textAlignment = .center;
    self.navigationItem.titleView = tlabel

Upvotes: -1

Related Questions