• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hanging Indentation in NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hanging Indentation in NSTextField


  • Subject: Re: Hanging Indentation in NSTextField
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 30 Mar 2006 09:47:24 -0800


On Mar 30, 2006, at 8:05 AM, Ryan Stevens wrote:

On Mar 29, 2006, at 6:07 AM, Greg Wiseman wrote:


Since we're dealing with textfields, it seems to make sense that we
need to attach it to the field editor. I tried simply calling
replaceTextContainer: on the field editor when editing of the fields
begins, in the textfield delegate's controlTextDidBeginEditing method.
It works beautifully until editing finishes, then the lines are no
longer indented.
...
I would use NSAttributedStrings instead. Make a NSMutableParagraphStyle with 5 or 10 for its headIndent and reuse/ apply that to each NSAttributedString before giving them to your text fields...

NSParagraphStyle, -headIndent ...
Returns the distance in points from the leading margin of a text container to the beginning of lines other than the first.


Sounds like it'll do exactly what you want. :D

Yes, the issue here is that when a text field isn't editing, it doesn't have the field editor, and the text is actually drawn by the cell using NSStringDrawing or the equivalent. If you really needed to use a custom text view, text container, layout manager, etc., you would need to use NSTextViews in place of NSTextFields.


Greg, for a professed newcomer you seem to have quite a grasp of the text system. Your solution sounds like a good one if what you really want is to shape the region in which text is drawn, independent of anything in the text itself.

The alternative solution that Ryan is proposing is to use the firstLineHeadIndent and headIndent of the paragraph style, which will produce the sort of indentation you are talking about for each paragraph of text--that is, it will start over after every \n. You can easily experiment with this in TextEdit by making sure that the ruler is displayed, and moving the two indicators at the far left of the ruler, placing the T-shaped one to the left of the downward pointing arrow.

Typically a textfield would contain only one paragraph of text, and if that's the case then modifying the paragraph style should produce the effect you are looking for. It's not impossible for a text field to contain more than one paragraph--for example, opt-return can be used to insert a \n in one--but it's not common. Depending on the contents of your text fields, the paragraph style solution could work for you.

Douglas Davidson

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Hanging Indentation in NSTextField (From: "Greg Wiseman" <email@hidden>)
 >Re: Hanging Indentation in NSTextField (From: Ryan Stevens <email@hidden>)

  • Prev by Date: Re: Getting Carbon events in Cocoa
  • Next by Date: Re: Distro?
  • Previous by thread: Re: Hanging Indentation in NSTextField
  • Next by thread: Is automatically scaling NSImage in cell?
  • Index(es):
    • Date
    • Thread