• 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: is this string styled?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: is this string styled?


  • Subject: Re: is this string styled?
  • From: Camillo Lugaresi <email@hidden>
  • Date: Sat, 7 Jan 2006 16:16:27 +0100

On 07/gen/06, at 15:57, Matt Neuburg wrote:

I have an NSTextView. To save storage space, if what's in the text view is
effectively unstyled, I'd like to save just the NSString version of it, not
the whole NSAttributedString. Is there a simple way to ask the
NSAttributedString: "Are your attributes the same as what I'd get if I took
your string, made an NSAttributedString from it using initWithString, and
stuck it in that NSTextView?" (The reason I'm having trouble with this is
that the attributes of an attributed string made with initWithString form an
empty dictionary, but the attributes of that same attributed string when it
has passed thru the text view are no longer empty.) m.

First, determine if the entire string is covered by the same attribute set using attributesAtIndex:longestEffectiveRange:inRange:. If it is, compare that attribute set with the default attribute set (which depends on your application).


Of course, there is a difference between a string that uses Helvetica because it is the default font for that text view, and one that the user has explicitly chosen to be in Helvetica. If the default is changed to Times (eg in your application's preferences), you'll probably want the former to be displayed in Times, and the latter in Helvetica. You can't tell these two cases apart based on the current attribute set of a string: you need to find another way to do it. For example, you could have a plain text and styled text mode like TextEdit or Mail, or you could set a custom "use default style" attribute on the entire string, and then hook into the text system to clear your custom attribute whenever the user sets any style attributes on a range of characters.

Camillo
_______________________________________________
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: is this string styled?
      • From: Matt Neuburg <email@hidden>
References: 
 >is this string styled? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: is this string styled?
  • Next by Date: Re: Interface declaration
  • Previous by thread: is this string styled?
  • Next by thread: Re: is this string styled?
  • Index(es):
    • Date
    • Thread