Reputation: 1890
I have a NSTextField
(Label) in a NSView
. Value in the label changes dynamically. I would like to set the Frame of the TextField always centered with respect to view.Is there any way to calculate the pixels or size occupied by the text in the texfield so that I can increase the size of the textfield to fit the text and change the origin so that textfield is always centered.
I would like to align the NSTextField
to be Centered with in a View and Change the origin and frame of the textfield by calculating the size occupied by text. How to calculate the size occupied by the text in the TextField ?
Upvotes: 0
Views: 287
Reputation: 5589
Unless the label has a background color the easiest thing is to size it to be as large as your UI can possibly allow and then set your text justification to be centering. You can do this in Interface Builder by just selecting the centering tab under "Alignment" in the Attributes Inspector for the label.
Upvotes: 4