Skip navigation.
 
mlRe: Silly NSTextFieldCell tricks
FROM : John Stiles
DATE : Thu Jan 31 22:37:15 2008

Peter Ammon wrote:
>
> On Jan 31, 2008, at 11:56 AM, John Stiles wrote:
>

>> Peter Ammon wrote:

>>>
>>> On Jan 31, 2008, at 11:27 AM, John Stiles wrote:
>>>

>>>> I've noticed that in table views, the NSTextFieldCell has the
>>>> ability to ever-so-slightly squash its contents horizontally, to
>>>> fit inside the table cell, before eventually giving up and
>>>> truncating them with ellipses.
>>>>
>>>> Is there any way for me to programmatically do the same thing to my
>>>> own NSTextFieldCell?
>>>>
>>>> As I'm typing this, suddenly I'm thinking "maybe I could fake it by
>>>> altering the cell's bounds while leaving the frame alone"… but is
>>>> there a better way? Changing the bounds would make the text
>>>> thinner, which isn't quite the same as squeezing the letters more
>>>> tightly together.

>>>
>>> Hi John,
>>>
>>> This is called "tightening" in the API, and it's enabled by default
>>> on text fields (actually, on any control) when the line break mode
>>> is one of the three truncation line break modes in
>>> NSParagraphStyle.h.  You can control the threshold between
>>> tightening and truncation with the setTighteningFactorForTruncation:
>>> method on NSMutableParagraphStyle.
>>>
>>> Hope that helps,
>>> -Peter

>> Cool!
>> Is there any way to enable this for an NSTextField in a window?
>> Someone off-list suggested using attributed strings to do this, but
>> is that the best way?

>
> Attributed strings aren't necessary, and NSTextFields do this by
> default.  In IB, make an NSTextField and in the Inspector, set its
> Line Breaks mode to Truncate Tail, and make it resize with the window.


Wait, I'm confused—how do I control the tightening factor on an
NSTextField? I can set its line-break mode, but there doesn't seem to be
a way to set its paragraph style or its tightening factor. Or is this a
case where I need to use attributed strings after all?

Related mailsAuthorDate
mlSilly NSTextFieldCell tricks John Stiles Jan 31, 20:27
mlRe: Silly NSTextFieldCell tricks Peter Ammon Jan 31, 20:53
mlRe: Silly NSTextFieldCell tricks glenn andreas Jan 31, 20:55
mlRe: Silly NSTextFieldCell tricks John Stiles Jan 31, 20:56
mlRe: Silly NSTextFieldCell tricks Peter Ammon Jan 31, 21:12
mlRe: Silly NSTextFieldCell tricks John Stiles Jan 31, 21:16
mlRe: Silly NSTextFieldCell tricks John Stiles Jan 31, 22:37
mlRe: Silly NSTextFieldCell tricks Aki Inoue Jan 31, 22:51
mlRe: Silly NSTextFieldCell tricks John Stiles Jan 31, 22:54