Re: Making NSView auto resize to fit contents of NSTextView
Re: Making NSView auto resize to fit contents of NSTextView
- Subject: Re: Making NSView auto resize to fit contents of NSTextView
- From: PCWiz <email@hidden>
- Date: Fri, 23 Oct 2009 20:27:42 -0600
Tried this with my NSCollectionViewItem's view. I first subclassed
NSCollectionViewItem and added this method:
- (void)awakeFromNib
{
[(AutoResizingView* )[self view] setup];
}
Basically just calls the "setup" method of the NSCollectionView's
view. Then this is my setup method in the subclass of NSView:
- (void)setup
{
[[tv textContainer] setLineFragmentPadding:0.0];
(void) [[tv layoutManager] glyphRangeForTextContainer:[tv
textContainer]];
[self setFrame:NSMakeRect([self frame].origin.x, [self
frame].origin.y, [self frame].size.width, [[tv layoutManager]
usedRectForTextContainer:[tv textContainer]].size.height)];
}
"tv" is the NSTextView. What I end up with is this:
http://img24.imageshack.us/img24/710/screenshot20091023at825.png
Each of the little grey bubbles is an NSCollectionViewItem, and it
seems to be deformed.
On 2009-10-23, at 6:06 PM, Graham Cox wrote:
On 24/10/2009, at 10:43 AM, PCWiz wrote:
I basically need a way of getting the height of the text view
needed to display all the text.
Welcome to the wonderful world of the Cocoa text system! You need to
go deeper into the text system and look at the NSLayoutManager object:
- (NSRect)usedRectForTextContainer:(NSTextContainer *)aTextContainer
file:///Developer/Documentation/DocSets/com.apple.adc.documentation.AppleSnowLeopard.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/TextLayout/TextLayout.html
This is listed as a common task in that document: "Calculating Text
Height"
--Graham
_______________________________________________
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