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!
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!