Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rezeda

macrumors newbie
Original poster
Nov 11, 2008
10
0
Hi all!

I want to create an NSTextField as big as the NSString that should be displayed in it.

I tried the following code:

NSString *myString = @"blabla blabla";
NSUInteger len =[myString length];

NSFont* mySystemFont = [NSFont systemFontOfSize:[NSFont systemFontSize]];
NSRect mySystemFontRect = [mySystemFont boundingRectForFont];


NSRect textFieldRect = NSMakeRect(0,0,len*mySystemFontRect.size.width,20);


But the NSTextField that I created next using this textFieldRect, is far too big (width is too big) for my string!

What I actually want to ensure is that, no matter what the font is, the NSTextField will display the entire string.
Anyone has any idea what should I try next?

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.