I have an UINavigationBar added to my UIViewController view. I want to change the fonts properties. Note that I want to change a UINavigationBar not controller. In my app where I use UINavigationController I use self.navigationItem.titleView = label;
to display the custom label.
How can I accomplish to have a custom title in my UINavigationBar?
P.S I use this to set the title text self.navBar.topItem.title = @"Information";
of my UINavigationBar.
let navigation = UINavigationBar. appearance() let navigationFont = UIFont(name: "Custom_Font_Name", size: 20) let navigationLargeFont = UIFont(name: "Custom_Font_Name", size: 34) //34 is Large Title size by default navigation.
Hold the command key and click the text to bring up a pop-over menu. Choose Show SwiftUI Inspector and then you can edit the text/font properties.
To change a navigation bar color in SwiftUI, you apply toolbarBackground modifier to the content view of NavigationStack . NavigationView is deprecated in iOS 16. toolbarBackground accepts two parameters. ShapeStyle : The style to display as the background of the bar.
Start with Navigation ControllerCreate a single view application in Xcode. Add two view controller into your storyboard. Create two different swift files for those view controllers and set identifiers for them. Take a button in each view controller, set constrain for them and customize as you want.
From iOS 5 onwards we have to set title text color and font of navigation bar using titleTextAttribute Dictionary(predefined dictionary in UInavigation controller class reference).
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"ArialMT" size:16.0], NSFontAttributeName,nil]];
The below tutorial is the best tutorial for customization of UIElements like UInavigation bar, UIsegmented control, UITabBar. This may be helpful to you
http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5
(This is not possible using the new iOS 5.0 Appearance API).
Edit:
iOS >= 5.0 :
Set the Title Text Attributes for the Navigationbar:
// Customize the title text for *all* UINavigationBars NSDictionary *settings = @{ UITextAttributeFont : [UIFont fontWithName:@"YOURFONTNAME" size:20.0], UITextAttributeTextColor : [UIColor whiteColor], UITextAttributeTextShadowColor : [UIColor clearColor], UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]}; [[UINavigationBar appearance] setTitleTextAttributes:settings];
iOS < 5.0
UINavigationItem doesn't have a property called label or something, only a titleView. You are only able to set the font by setting a custom label as this title view You could use the following code: (as suggested here)
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)]; label.font = [UIFont fontWithName:@"YOURFONTNAME" size:20.0]; label.shadowColor = [UIColor clearColor]; label.textColor =[UIColor whiteColor]; label.text = self.title; self.navigationItem.titleView = label; [label release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With