Thanks for your respons, but I need the exacte size in points, which means
drawing with the right Font etc.
So here's where I am
in
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
I'm calling a function which calculates the height needed for the text and
that's what I'm returning:
-(float)heightForStringDrawing:(NSString*)theTextField withFont:(NSFont*)myFont
forWidth:(float)myWidth{
NSTextStorage *textStorage = [[[NSTextStorage alloc]
initWithString:theTextField] autorelease];
NSTextContainer *textContainer = [[[NSTextContainer alloc]
initWithContainerSize: NSMakeSize(myWidth, FLT_MAX)] autorelease];
NSLayoutManager *layoutManager = [[[NSLayoutManager alloc] init]
autorelease];
[layoutManager addTextContainer:textContainer];
[textStorage addLayoutManager:layoutManager];
[textStorage addAttribute:NSFontAttributeName value:myFont
range:NSMakeRange(0,[textStorage length])];
[textContainer setLineFragmentPadding:0.0];
[layoutManager glyphRangeForTextContainer:textContainer];
return [layoutManager
usedRectForTextContainer:textContainer].size.height;
}
BUT, I'm getting row clippings, and the strange thing if as soon as I'm
clicking on any cell, everything comes back to good order.
Any help appreciated,
Michael
On 8 nov. 2010, at 20:32, [email protected] wrote:
>
> On 8 Nov 2010, at 08:55, Micha Fuhrmann wrote:
>
>> Dear All,
>>
>> I'm stuck here and it seems so trivial...
>>
>> I'm using NSTextFieldCell in a tableview and when the text takes the whole
>> cell, the cell size doesn't resize and add a line (which I would expect!!!).
>> Setting the text properties in NSCell doesn't cut it either. So I've tried
>> using
>>
>> - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
>>
>> But how can I compute the amount screen pixels my NSString that's going into
>> the cell will take to return a height with the proper number of lines? I
>> must be missing something, it's just too silly.
>>
>> Any help appreciated.
>>
>> Michael
>>
>>
> For cell text wrapping behaviour see the NSCell documentation:
> -setLineBreakMode, -setWraps, -setTruncatesLastVisibleLine:
>
> To get the required size try NSString -sizeWithAttributes:
>
> Regards
>
> Jonathan Mitchell
>
> Developer
> Mugginsoft LLP
> http://www.mugginsoft.com
>> This email sent to [email protected]
>
> _______________________________________________
>
> Cocoa-dev mailing list ([email protected])
>
> 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/michaf%40mac.com
>
> This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
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]