TextField truncate beginning with AttributedString

Discussion in 'Mac Programming' started by WhiteRabbit, May 12, 2009.

  1. WhiteRabbit macrumors newbie

    Joined:
    Jan 11, 2005
    #1
    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.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    I think NSCell overrides the value inside the attributed string. Did you try setting setLineBreakMode: on the textfield cell directly?
     
  3. WhiteRabbit thread starter macrumors newbie

    Joined:
    Jan 11, 2005
    #3
    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.
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. WhiteRabbit thread starter macrumors newbie

    Joined:
    Jan 11, 2005
    #5
    Yep that's what it took. Thanks. It's also comes with an elipsis, quite slick.
     

Share This Page