0

I have developed an iOS app that I have localized in both French and English. I have a UIButton in my UINavigationBar that reads Back in English and Retournerin French. My UIButton seems to just take the length from the English button as default so when the app is opened on a French device the text doesn't fit in the button.

I've tried having the UIButton read Retourner in my Storyboard and I can't seem to set a constraint for the length. Am I missing something?

user3185748
  • 2,478
  • 8
  • 27
  • 43
  • Maybe you can use this answer http://stackoverflow.com/questions/4135032/ios-uibutton-resize-according-to-text-length – Kimdv Feb 01 '15 at 17:07
  • The methods indicated there were depreciated with iOS 7. Is there a way to do this with IB? – user3185748 Feb 01 '15 at 17:10

2 Answers2

1

Try this then

button.titleLabel?.adjustsFontSizeToFitWidth = true

Found in: How to adjust font size of text in a UIButton to fit the width programmatically in Swift?

Community
  • 1
  • 1
Kimdv
  • 310
  • 2
  • 12
  • This makes the text fit but it does this by shrinking the text so now it fits but is hard to read. How can this be done by elongating the button? – user3185748 Feb 01 '15 at 17:48
0

Well it turns out theres a provided method for this!

I just set:

backButton.sizeToFit()

In my viewDidLoad and it worked like a charm.

user3185748
  • 2,478
  • 8
  • 27
  • 43