How to center an NSTextField in a view

I have an NSTextField (label) with center IB in the view with the text "__DRAG_AND_DROP_YOUR_MEDIA_HERE". My controller uses NSLocalizedString to convert text:

Russian .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 source text "__DRAG_AND_DROP_YOUR_MEDIA_HERE" is in the view. Translated text is not central (depending on length). All translated texts begin with the same abscissa x as the orignal text. How can I fix this problem?

PS: I do not want to play with setFrame, height, width just for a simple point like this. I guess there is another way to do this.

Thanks.

+6
source share
1 answer

Set the textbox alignment to NSCenterTextAlignment . You can do this from IB or programmatically using -setAlignment:

+14
source

Source: https://habr.com/ru/post/917280/


All Articles