• 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: OK, but what do 'attributes' look like?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OK, but what do 'attributes' look like?


  • Subject: Re: OK, but what do 'attributes' look like?
  • From: mmalcolm crawford <email@hidden>
  • Date: Mon, 8 Mar 2004 22:31:30 -0800

On Mar 8, 2004, at 10:03 PM, Denis Stanton wrote:
can some one help me out with understanding the Cocoa documentation? I
think this is one of those things that is considered so obvious that
the worthy documenters never bother to write it down.
Umm, from the class description of NSAttributedString:
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ ObjC_classic/Classes/NSAttributedString.html>
I'm guessing the "Umm," prefix is shorthand for "this is so obvious. Why doesn't he read the documentation?"

No, it's shorthand for, "I'm sorry if I'm telling you something you're already aware of".

My problem is that I did read it but the documentation is not as obvious to me as it was to the person who wrote it.
"Constants
An attributed string identifies attributes by name, storing a value under the name in an NSDictionary. You can assign any attribute name/value pair you wish to a range of characters, in addition to the standard attributes described in the Constants section of NSAttributedString Additions."
This appears to tell me that I am free to think up any name value pair I want to.

Yes, that's exactly what it means.

"You can assign any attribute name/value pair you wish ". This doesn't make sense to me. Surely for the text to appear in a certain font I have to identify that font using a name that the compiler will recognise. Making up my own key value pair will not communicate anything useful.

It allows for flexibility -- suppose you wanted to mark up text with special attributes for class names. Apple hasn't provided an attribute for that, but you can create, and assign, your own...


What I'm looking for is the key value for "font name". (No, it isn't "Font name".) and even some suggested names of fonts, so that I will know how the compiler would like to see them punctuated or capitalized (or is that "cased"?)

Clicking on the link to Constants takes you to:
<http://developer.apple.com/documentation/Cocoa/Reference/ ApplicationKit/ObjC_classic/Classes/NSAttributedString.html>

Yes, I went there. I found:
Attribute Identifier NSFontAttributeName
Default Value Helvetica 12-point

I'm not sure why you skipped the Value Class -- NSFont?

so I wrote:
[myString drawInRect: myRect with attributes: [NSDictionary dictionaryWithObject @"Helvetica 12-point" forKey: NSFontAttributeName]];
The compiler was happy, but at run time I get an error:
*** -[NSConstantString pointsize]: selector not recognized
Unfortunately at that point (no pun intended) I became lost. Which string is the NSConstantString? and who asked for its "pointsize"

The string is the string you passed instead of an NSFont object.

What would be really nice would be just one example that works,.

NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]];

NSDictionary *attributes =
[NSDictionary dictionaryWithObject:font forKey: NSFontAttributeName];

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: OK, but what do 'attributes' look like?
      • From: Denis Stanton <email@hidden>
    • Re: OK, but what do 'attributes' look like?
      • From: mmalcolm crawford <email@hidden>
References: 
 >Re: OK, but what do 'attributes' look like? (From: Denis Stanton <email@hidden>)

  • Prev by Date: Re: Encapsulate C struct/toll-free bridging?
  • Next by Date: Re: OK, but what do 'attributes' look like?
  • Previous by thread: Re: OK, but what do 'attributes' look like?
  • Next by thread: Re: OK, but what do 'attributes' look like?
  • Index(es):
    • Date
    • Thread