Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My navigation bar's large title is too wide. How to fix that?

I am using navigation controller, and I've set to true its navigation bar's prefersLargeTitle property. Everything works fine, but when the text of my title becomes too big, it doesn't fit in space. Here how it looks:

enter image description here

Is it possible to somehow make the title (while the navigation bar's prefersLargeTitle property is set to true) dynamically adjust its font size, and if it is so, how to achieve that?

like image 504
Tigran Iskandaryan Avatar asked Nov 06 '17 22:11

Tigran Iskandaryan


People also ask

How do you change the title of a navigation?

Use navigationBarTitle(_:) to set the title of the navigation bar. This modifier only takes effect when this view is inside of and visible within a NavigationView .

What is Scrolledgeappearance?

The appearance settings for the navigation bar when the edge of scrollable content aligns with the edge of the navigation bar. iOS 13.0+ iPadOS 13.0+ Mac Catalyst 13.1+ tvOS 13.0+


1 Answers

All you need is:

UILabel.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).adjustsFontSizeToFitWidth = true

Working also with SwiftUI on iOS 15.

like image 190
Sound Blaster Avatar answered Oct 08 '22 03:10

Sound Blaster