Changing UINavigationBar font in Swift
Posted
by
dcgoss
on Stack Overflow
See other posts from Stack Overflow
or by dcgoss
Published on 2014-08-24T22:17:14Z
Indexed on
2014/08/24
22:19 UTC
Read the original article
Hit count: 285
I have a UINavigationBar
with a title in the middle. I have added a custom font ("Comic_Andy.ttf
") to my app (I have checked info.plist
to make sure it's listed, and I have checked the Copy Bundle Resources
to make sure it has been added), and I would like the title of the UINavigationBar
to be displayed in that font. From what I can gather it seems as though I'm supposed to use this in my ViewController
:
myNavigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Comic_Andy", size: 22)]
I placed that method in the viewDidLoad
function of the ViewController
.
I have also tried this in the didFinishLaunchingWithOptions
function of the AppDelegate
:
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Comic_Andy", size: 22)]
I am programming in Swift, in XCode 6 Beta 6. Many resources regarding this task have mentioned using a method called setTitleTextAttributes
, which is nowhere to be seen. I can't figure it out for the life of me - I've probably spent close to 3 hours on it by now - I have checked every StackOverflow answer, every website, so please do not mark this as a duplicate.
Many thanks in advance!
© Stack Overflow or respective owner