PDA

View Full Version : TextField truncate beginning with AttributedString




WhiteRabbit
May 12, 2009, 11:51 AM
I want to have a non-editable TextField with one line of text that gets the beginning truncated so that you only see the end. The Truncate Head option seems like it only has an effect when editing.

I am using an AttributedString to set the value of the TextField with. I suspect that there may be an attribute of an AttributedString to set this but I can't find it.

I also want the field to be left alligned when the text fits within.



kainjow
May 12, 2009, 11:54 AM
I think NSCell overrides the value inside the attributed string. Did you try setting setLineBreakMode: on the textfield cell directly?

WhiteRabbit
May 12, 2009, 12:11 PM
Thanks, but that doesn't work either. I tried changing the allignment in the cell and the attributed string is overriding it. It also seems that IB automatically changes the options on the textfieldcell when the textfield is changed.

Is there a way to check if text is fitting within a cell? If so, I could chop the string myself. It might even be nicer since I could include an elipsis.

kainjow
May 12, 2009, 12:23 PM
If the cell isn't overriding it, then you should be able to provide in your NSAttributedString an NSParagraphStyleAttributeName (NSMutableParagraphStyle) and setup the line break mode there.

WhiteRabbit
May 12, 2009, 12:53 PM
Yep that's what it took. Thanks. It's also comes with an elipsis, quite slick.