Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Truncating the string value of an NSTextField, in a Panther compatible way.



Hey Everyone,

I'm trying to determine the best way to enable an NSTextField to truncate its stringValue (using one of the NSLineBreakMode options) if that value is too long and won't entirely fit into the field's frame. My text field has been sized in Interface Builder so that it will shrink as the window around it is made smaller.

Before you hit reply: I realize this is very simple on 10.4 or later, with a message to a cell's setWraps:YES and setLineBreakMode:. IB also allows both of these attributes to be set easily.

I'm in need of a solution that will work on 10.3.9+, however. The setLineBreakMode: method was added to the AppKit in Tiger <http:// developer.apple.com/releasenotes/Cocoa/AppKit.html>. The archives and other usual resources, for the most part, only turned up ideas about adding this behavior to text inside an NSTableView.

Using an attributed string seemed like a good way to make this happen. So, I created one with its NSParagraphStyleAttributeName set to a style with my desired line breaking mode. Then, I just called setAttributedStringValue: on the NSTextField. This didn't work, though, and I then tried changing the setWraps attribute of the text field in case that was the problem. The text field does handle string attributions correctly (such as fonts) but seems to ignore the paragraph style's line break mode.

For reference, Apple has a sample code listing in an article about truncating strings, <http://developer.apple.com/documentation/Cocoa/ Conceptual/Rulers/Tasks/TruncatingStrings.html>, which is very similar to mine.

Is a subclass of NSTextField or NSTextFieldCell required to accomplish this, since handing it an attributed string doesn't seem to be enough? (Or am I missing something really simple - I hate when that happens!)

Thanks for your help,
Sean
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.