In OC, everyone must be very familiar with, so in Swift5, how to set the text of the navigation bar title?
Look at OC first.
self.navigationItem.title = @"Home";
self.navigationController.navigationBar.titleTextAttributes = @{
NSForegroundColorAttributeName: UIColor.redColor,
NSFontAttributeName: [UIFont systemFontOfSize:26 weight:UIFontWeightUltraLight]
};
[self.navigationController.navigationBar setBackgroundColor:UIColor.systemGray4Color];
SWIFT5 Writing:
self.title = "Homepage"
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red,NSAttributedString.Key.font: UIFont.systemFont(ofSize: 25, weight: .ultraLight)]
self.navigationController?.navigationBar.backgroundColor = UIColor.systemGray4
The point is NSATTRIBUTEDSTRING.KEY.FONT: