• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: horizontal sizeToFit of NSTextView or NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: horizontal sizeToFit of NSTextView or NSTextField


  • Subject: Re: horizontal sizeToFit of NSTextView or NSTextField
  • From: Manfred Schwind <email@hidden>
  • Date: Sun, 20 Apr 2008 20:37:15 +0200

Now I want to be able to calculate the optimal width of the view so that the entire text is visible.

This worked wonders for me:

http://www.cocoabuilder.com/archive/message/cocoa/2008/3/31/202752

This also does not solve my problem.
Getting the height of a text for a given width is easy and I've done that countless times.
Also getting the width of a string (layed out in one line if it has no newlines) is no problem.


But I have a different problem. I try to give an easier explanation of my problem:

I have a text view that has a height that can hold three lines of text. Now I have one long string (without newlines). When putting this string into the text view, the text is automatically wrapped around. But maybe - for the initial width of the view - it will need four (or more) lines instead of just three. Now I want to calculate the optimal (minimum) width of the text view, to that the string is wrapped around in just three (or less) lines.

In the meantime I guess I have the solution. I don't think that there is really a way in Cocoa or Quartz that solves this problem. So I really have to "try" different widths, let the layout manager layout the text and see how much lines it needs. So I can do a "binary search" to get an ideal width.
Even if Cocoa or Quartz would have a method for calculating the width, it would internally also have to do such a binary search. I don't think that it's possible to calculate the perfect width in one step.
So I just do it myself and it works quite well.


Thanks for your attention,
Mani

_______________________________________________

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: horizontal sizeToFit of NSTextView or NSTextField
      • From: Jack Repenning <email@hidden>
References: 
 >horizontal sizeToFit of NSTextView or NSTextField (From: Manfred Schwind <email@hidden>)
 >Re: horizontal sizeToFit of NSTextView or NSTextField (From: Jack Repenning <email@hidden>)

  • Prev by Date: Re: drawRect: called twice for NSView subclass.
  • Next by Date: Re: Passing a C String as an argument
  • Previous by thread: Re: horizontal sizeToFit of NSTextView or NSTextField
  • Next by thread: Re: horizontal sizeToFit of NSTextView or NSTextField
  • Index(es):
    • Date
    • Thread