Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField Size



I've started to have a good look at those links and am trying to extract the stuff I need, I suppose I could try and use it complete, but they seem over complicated!!

This should do the trick:

NSRect bounds = NSMakeRect( 0, 0, [textField frame].size.width, 99999 );
[textField setStringValue:message];
float requiredHeight = [[textField cell] cellSizeForBounds:bounds].height;


(untested, typed in Mail)

~Martin



That was exactly what I needed - thanks!

I was stuggling to extract the code from the links, I think the fact the height is a float got in the way?!?! Seems odd to me, but works!

Just for completeness, my final code, which resizes the window, and catches short strings to keep the window above a minimum height:
NSRect bounds = NSMakeRect( 0, 0, [alertMessage frame].size.width, 99999 );
[textField setStringValue:message];
float requiredHeight = [[alertMessage cell] cellSizeForBounds:bounds].height;
if (requiredHeight < 52) requiredHeight = 52;
[theDialogWindow setContentSize:NSMakeSize(423, requiredHeight+106)];


Many thanks

Ben.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >parsing string data (From: "C Sandeep" <email@hidden>)
 >Re: parsing string data (From: j o a r <email@hidden>)
 >Re: parsing string data (From: "C Sandeep" <email@hidden>)
 >NSTextField Size (From: Ben Robinson <email@hidden>)
 >Re: NSTextField Size (From: "I. Savant" <email@hidden>)
 >Re: NSTextField Size (From: Ben Robinson <email@hidden>)
 >Re: NSTextField Size (From: Martin Wierschin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.