简体   繁体   中英

Navigation Bar Title - Change Font without changing size

I'm having trouble to change both the regular and large titles of my Navigation Bar. I only want to change the font, without interfering on the font size. I tried getting the pointSize, but it's not available for NavBar titles. How can I do it?

There is no way to change only font size. Since the font represents both size and the font itself.

Solution : change the font (both size and font) but set the default size. If you haven't made any changes to your project regarding the size then it's 17 by default. I tested it out and found it out.

So here is what you can do:

let attributes: [NSAttributedStringKey: Any] = [
        NSAttributedStringKey.font: YourFontOfSize(size: 17.0)
    ]

navigationController?.navigationBar.titleTextAttributes = attributes

Hope it helps! Please let me know if it worked.

UPDATE: Navigation bar also has a property called .largeTitleTextAttributes . So you can do the same as I did for .titleTextAttributes : Find out the default size by just trying to set the system font with sizes: 15, 16, 17 etc. And then when the size matches you will know which is the default size. And then apply your custom font using the default size that you found out.

Well There is a way but not programmatically. You can manually set the different font sizes from the utility panes in attribute inspector.

] [

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM