I have a view that has a fixed height and that should be filled with text (at runtime, but the text keeps static once set). Now I want to be able to calculate the optimal width of the view so that the entire text is visible. The text may wrap around. I tried a zillion things with NSTextView and sizeToFit (e.g. setHorizontallyResizable:YES and setVerticallyResizable:NO), but nothing worked.

The best result I got was a width that is able to hold the entire text in one long line. But I have a fixed height that can hold more than just one line of the text. That should be used! I want to get the optimal width so that the text can be placed into the view for a given height and the text can be wrapped if necessary.

Calculating the height for a fixed width is easy (there are several solutions and it was often asked in this mailing list), but calculating the width for a given height seems to be impossible.

Do I have to do kind of a "binary search" to get the optimal width? So trying different widths, laying out the text and checking its height if it fits into my fixed height?!? This must be possible (and should be fast enought, because the text is short and I only have to do it once in my app), but I would prefer an easier solution. ;-)

Any thoughts?

Regards,
Mani
--
http://www.mani.de
iVolume - Loudness adjustment for iTunes.
LittleSecrets - The encrypted notepad.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to