3

I have two language versions(English, Chinese) in my app. I would like to change button language text into these languages when user click on "Change Language" button.
For example,

 btnLogOut.setTitle(NSLocalizedString("Logout", comment: ""), for: .normal)


In Chinese language, the text does not show completely. So, I would like to change the font size when button text is translated into Chinese.
I don't want to change font size in English version. The Default font size for this button is "System Font. 15"

btnLogOut.setTitle(NSLocalizedString("Logout", comment: ""), for: .normal, UIFont.buttonFontSize) <br>

I got error. Actually , I added as a testing. I don't know how to do it. Please help me.

May Phyu
  • 895
  • 3
  • 23
  • 47

1 Answers1

2

Well, one way is to check when the user changes the language. For example,

changeLanguage() // change language

if currentLanguage == "Chinese" {
    buttonLogout.titleLabel?.font = UIFont.boldSystemFont(ofSize: 12)
} else {
    buttonLogout.titleLabel?.font = UIFont.boldSystemFont(ofSize: 15)
}
enter code here

Depending on how you implement the changing of language, you can have some kind of flag that checks whatever the current language is then change the font size to what you want.

Or another way is:

buttonLogout.titleLabel.adjustsFontSizeToFitWidth = true
Lysdexia
  • 453
  • 8
  • 22