Elfoiros
Elfoiros

Reputation: 468

How to center a NSTextField in a view

i've a NSTextField (label) centered with IB in a view with the text "__DRAG_AND_DROP_YOUR_MEDIA_HERE". In my controller a use NSLocalizedString to translate the text :

English.lproj/Localizable.strings :

"__DRAG_AND_DROP_YOUR_MEDIA_HERE" = "Drag & Drop your media here"

French.lproj/Localizable.strings :

"__DRAG_AND_DROP_YOUR_MEDIA_HERE" = "Déposer vos média ici"

Only the initial text "__DRAG_AND_DROP_YOUR_MEDIA_HERE" is centerred in the view. The translated text is not centerrd (depending on is lenght). All the translated text start at the same absciss x than the orignal text. How can i fix this issue ?

PS: I don't want to play with setFrame, height, width just for a simple point like this. I guess there's another method to do this.

Thanks.

Upvotes: 6

Views: 7224

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90521

Set the text field's alignment to NSCenterTextAlignment. You can do this from IB or programmatically using -setAlignment:.

Upvotes: 15

Related Questions