• 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: Get the number of lines of text in an NSTextView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get the number of lines of text in an NSTextView?


  • Subject: Re: Get the number of lines of text in an NSTextView?
  • From: Todd Ditchendorf <email@hidden>
  • Date: Tue, 24 Jan 2006 17:34:15 -0600

Thanks Doug. Um, I'm only wanting to count line breaks, as I have configured my NSTextView and its NSScrollView to NOT wrap text.

So line breaks should do it.

I've just found the following code snippet in Apple's docs... it does the trick. I was thinking that some internal structure might track the number of lines, but between what you're saying and the fact that this mini-algorithm is in the apple docs, that there's no such animal. Can anyone confirm/deny?

NSString *s = [aTextView string];
unsigned numberOfLines, index, stringLength = [s length];

for (index = 0, numberOfLines = 0; index < stringLength; numberOfLines++) {
index = NSMaxRange([s lineRangeForRange:NSMakeRange(index, 0)]);
}
return numberOfLines;



Todd Ditchendorf http://ditchnet.org http://scan.dalo.us (Cocoa Developer Tools)

_______________________________________________
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


  • Follow-Ups:
    • Re: Get the number of lines of text in an NSTextView?
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Re: Get the number of lines of text in an NSTextView?
  • Next by Date: Re: Get the number of lines of text in an NSTextView?
  • Previous by thread: Re: Get the number of lines of text in an NSTextView?
  • Next by thread: Re: Get the number of lines of text in an NSTextView?
  • Index(es):
    • Date
    • Thread