[SWIFT] Countermeasures for forgetting to specify the font when titleTextAttributes is specified

Overview

When I specified titleTextAttributes to change the text color of the iOS navigation bar, the font was broken, so I coped with it.

environment

Xcode 11.3 iOS 14.0 & 13.3

Event

If the font is specified in the navigation bar title, Even if only the color is specified, the font specification is not specified.

--If the font is Hiragino Kaku Gothic (with xib) スクリーンショット 2020-10-16 16.30.05.png

--If you want to change the color of the title on a specific screen and specify only the color as is often the case, the font specification will be removed (is it the system default?)

    self.navigationController?.navigationBar.titleTextAttributes = [
      //Text color
       .foregroundColor: UIColor.yellow
    ]

スクリーンショット 2020-10-16 16.29.42.png

Countermeasures

--You also need to add the font specification

    self.navigationController?.navigationBar.titleTextAttributes = [
        NSAttributedString.Key.foregroundColor: UIColor.yellow,
        NSAttributedString.Key.font: UIFont(name: "HiraginoSans-W3", size: 16) as Any
    ]

スクリーンショット 2020-10-16 16.36.08.png

It's natural, but I didn't notice it, so I'll post it as a memorandum.

Recommended Posts

Countermeasures for forgetting to specify the font when titleTextAttributes is specified
When the hover of Eclipse is hard to see
What is the constructor for?
Is it easy for the user to use when implementing general-purpose functions? Let's be aware of
When the character string passed to C ++ by JNA is garbled
How to output the value when there is an array in the array
How to write the view when Vue is introduced in Rails?
[WSL] Solution for the phenomenon that 404 is displayed when trying to insert Java with apt (personal memo)
How to specify validation for time_field
[IOS] What to do when the image is filled with one color
Change the processing when the button on RecyclerView is pressed for each list
[Docker] How to build when the source code is bind-mounted on the container
[Java small story] Monitor when a value is added to the List
[Ruby] How to prevent errors when nil is included in the operation