Re: Truncating strings to fit a text field
Re: Truncating strings to fit a text field
- Subject: Re: Truncating strings to fit a text field
- From: Ryan Stevens <email@hidden>
- Date: Thu, 25 Mar 2004 22:28:06 -0800
This has been covered and should be in the archives.
But anyway, you must [cell setWraps:YES]; and then use something like..
NSMutableAttributedString *yourString;
NSMutableParagraphStyle *truncateStyle = [[NSMutableParagraphStyle
alloc] init];
[truncateStyle
setLineBreakMode:NSLineBreakByTruncatingTail];
[yourString addAttribute:NSParagraphStyleAttributeName
value:truncateStyle range:NSMakeRange(0, [yourString length])];
[truncateStyle release];
On Mar 25, 2004, at 8:31 PM, Satoshi Matsumoto wrote:
>
Hi Mark,
>
>
on 04.3.26 0:50 PM, Mark Alldritt at email@hidden wrote:
>
> I want to display a file path in a NSTextField instance. I want to
>
> truncate
>
> a long file path with a ... (like I can do in Carbon with
>
> TruncString/TruncText). What's the magic incantation to make this
>
> happen in
>
> Cocoa?
>
>
>
> There is NSString's sizeWithAttributes, but I don't see anything that
>
> will
>
> "do the right thing" given an available width.
>
>
I don't know whether the system truncate routine exists in Cocoa, but
>
this
>
is my own truncate code for a long path.
>
>
truncName = [NSString stringWithFormat:@"%@ - .../%@",
>
[path lastPathComponent],
>
[[path stringByDeletingLastPathComponent]
>
lastPathComponent]];
>
>
Satoshi
>
-----------------------------------------------------
>
Satoshi Matsumoto <email@hidden>
>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.