• 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
workaround: stubborn text attributes in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

workaround: stubborn text attributes in NSTextView


  • Subject: workaround: stubborn text attributes in NSTextView
  • From: Andy Lee <email@hidden>
  • Date: Wed, 27 May 2009 17:58:50 -0400

I had a problem with NSTextView refusing to use the text attributes I assigned to it.  Here's my workaround in case anyone else runs into the same problem.

I configured an NSTextView in IB with a custom text color, a bit of dummy text with a custom font, and rich text turned off (i.e., it's plain text).  The problem was that when the user deletes all the text, the text view reverts to black Helvetica 12.

I googled "empty NSTextView site:cocoabuilder.com" and found some people had solved similar problems by writing a delegate method that futzes with the text view's typingAttributes.  I was about to try that but noticed my text view's typingAttributes was nil.  (The difference may be that the other people who had problems were using rich-text text views.)

After a bunch of trial and error I got it to work by temporarily changing the rich-text flag to YES and selecting some non-empty text:

		[myTextView setRichText:YES];
		[myTextView selectAll:nil];  // make sure text is non-empty
		//NSLog(@"typing attributes: %@", [myTextView typingAttributes]);
		[myTextView setRichText:NO];

It seems this forces the text view to set its typingAttributes, which it then dutifully applies in all subsequent editing.

I'll file a Radar when I get home, but I'm posting here now in case someone can tell me it's a known issue and/or I'm Doing It Wrong.  I have a vague feeling I'm missing something obvious.

Well, I'm also posting so I can paste a URL to this thread in my code comments. :)

--Andy


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: workaround: stubborn text attributes in NSTextView
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Abstract class with single subclass
  • Next by Date: Re: workaround: stubborn text attributes in NSTextView
  • Previous by thread: Re: Bindings and core data
  • Next by thread: Re: workaround: stubborn text attributes in NSTextView
  • Index(es):
    • Date
    • Thread