Navigation Bar Title background is white in iOS11 - ios

For some reason in iOS 11 the title label in navigation bar has a white background:
This is just a normal navigation controller and the title is being set the default way:
self.title = #"My Title";
This problem is only happening in iOS 11 and the screenshot was taken from the simulator, otherwise for previous iOS version this works fine.
Any suggestions as to how i can have a normal clear background label or remove the white background which is coming up for whatever reason?

Check if you have set the title text attributes correctly. You can set the title text attributes from the Storyboard or Programatically. Select Storyboard -> NavigationBar -> Go to attribute inspector -> Title Text Attributes
or in ViewController try setting it manually
Swift 4:
self.navigationController?.navigationBar.titleTextAttributes = [
NSAttributedStringKey.foregroundColor: UIColor.white,
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17, weight: .bold)
]
Swift 3:
self.navigationController?.navigationBar.titleTextAttributes = [
NSForegroundColorAttributeName: UIColor.white,
NSFontAttributeName: UIFont.systemFont(ofSize: 17, weight: .bold)
]

Related

Change Button Title in iOS 15

I am using new button configuration style as introduce in iOS 15. It works great!
But when I try to change the title, it is also change the font.
Ref similar issue: uibutton.setTitle change text without changing font size
I don't want to go back to old style :(
My try:
var config = self?.btnNext.configuration
config?.title = "New Title"
self?.btnNext.updateConfiguration()
Thank you,
Try using an attributedTitle so you can set the font:
config?.attributedTitle = AttributedString("your new title",
attributes: AttributeContainer([
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20.0), NSAttributedString.Key.foregroundColor: .black]))
Hope this helps.

Navigation bar title not bold

When I'm in the storyboard, the navigation bar title is shown as bold in the Storyboard as default but when you run the app in simulator and device, it isn't bold. Annoyingly it isn't possible to change the font size from interface builder.
Below you can see the difference between what's shown on interface builder and the simulator.
Interface builder:
Simulator:
I'm aware that I can change the font using something like this: self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "YOUR-FONT-NAME-WEIGHT", size: 24)!
That would be perfect but I want to keep the font to the default SF font.
Is there a workaround this? Any reason why this happens?
Use this code in your viewDidLoad to change font size
self.navigationController?.navigationBar.titleTextAttributes = [
NSFontAttributeName: UIFont.systemFont(ofSize: 20, weight: UIFontWeightHeavy)
]
For swift 4:
self.navigationController?.navigationBar.titleTextAttributes = [
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.heavy)
]
Before in simulator it looks like
And with that code, it looks like
Simply use UIFont.systemFont to get the default SF font.
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize:24, weight: .bold)]
Swift 4:
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.heavy)]

How can we disable the effect of enabled "bold text" from settings in the iphone (in my app)? - swift 2.0

If the user’s device has bold text enabled there are certain parts of the system that will automatically respond to that. For example, if you are using a default navigation controller in your app, the title and the UIBarButtonItem at the top of the screen will become bold.
How can I disable the effect of bold text to all my app and specially to the default navigation controller ( to the title and the UIBarButtonItem ) in my app ? - swift 2.0 ( iOS 8 & 9 ) . thx all : )
I have this code to detect if the bold text is enabled : (if it is useful)
if (UIAccessibilityIsBoldTextEnabled()) { // use bold font
}
else {
// use standard font
}
If your Bar Button Item is using default(System) font, and if the user enable bold text, your screen text changes Bold. Customize font of your bar button item with regular text.
let barButton = UIBarButtonItem.appearance()
if let font = UIFont(name: "HelveticaNeue", size: 19) {
barButton.setTitleTextAttributes([NSFontAttributeName: font], forState: UIControlState.Normal)
}

UINavigationBar cut off font

I'm using custom font in my application. I've used the code below in AppDelegate to change the UINavigationBar appearance.
let navigationBarAppearance = UINavigationBar.appearance()
navigationBarAppearance.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Pacifico", size: 20)!]
However, the font is getting cut off at the end of the string. The text is "Tell", but you can see that the last character is getting cut off. It works fine if I'm using the default font. Is this a problem with the font itself or it's a bug in Xcode?

Setting navigation bar text font in Xcode 6.1

I am using a non-default font in my apps navigation bar, and this worked absolutely fine prior to Xcode 6.1. Now I get an error on the line of code where I am defining the font type and colour.
This is my code:
var attributes = [NSForegroundColorAttributeName: UIColor.whiteColor(),NSFontAttributeName: UIFont(name: "Avenir", size: 24)]
self.navigationController?.navigationBar.titleTextAttributes = attributes
What do I need to change to get this to work again?
UIFont(name:size:) returns an optional, which cannot be used as the value.Change it to this:
var attributes = [NSForegroundColorAttributeName: UIColor.whiteColor(),NSFontAttributeName: UIFont(name: "Avenir", size: 24)!]
By doing this you unwrap the UIFont? value to NSFontAttributeName. I believe you have to make sure the font is actually there to avoid crash.

Resources