Update the width of NSTextField according to the length of the string

advertisements

I want to make a label that change its size depending on the size of the string value that it will show. Currently I am doing this:

[tfScroll setStringValue:strScoller];
[tfScroll sizeToFit];

However this is not working. What am I missing?


If you trying to resize the fields's height, this may works:

CGRect frame = tfScroll.frame;
frame.size.height = tfScroll.contentSize.height;
tfScroll.frame = frame;