• 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: NSMutableAttributeString, fonts and alignment
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableAttributeString, fonts and alignment


  • Subject: Re: NSMutableAttributeString, fonts and alignment
  • From: Ryan Dingman <email@hidden>
  • Date: Tue, 18 Dec 2001 23:53:58 -0800

Another way of doing this is by specifying the NSParagraphStyleAttributeName. Create a paragraph style, set its alignment and then add it to your attributes dictionary. Something like the following:

NSDictionary *attributes;
NSAttributedString *attributedString;
NSMutableParagraphStyle *paragraphStyle;

paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setAlignment:NSCenterTextAlignment];

attributes = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil];
attributedString = [NSAttributedString attributedStringWithString:@"My String" attributes:attributes];

Hope this helps.

ryan

--
Ryan Dingman
FrontBase, Inc.
email@hidden

On Tuesday, December 18, 2001, at 08:36 PM, Simson Garfinkel wrote:

Here is a section from NSAttributedString.h:

/* Predefined character attributes for text. If the key is not in the
dictionary, then use the default values as des\
cribed below.
*/
APPKIT_EXTERN NSString *NSFontAttributeName; /* NSFont, default
Helvetica 12 */
APPKIT_EXTERN NSString *NSParagraphStyleAttributeName; /*
NSParagraphStyle, default defaultParagraphStyle */
APPKIT_EXTERN NSString *NSForegroundColorAttributeName; /* NSColor, default
blackColor */
APPKIT_EXTERN NSString *NSUnderlineStyleAttributeName; /* int, default 0:
no underline */
APPKIT_EXTERN NSString *NSSuperscriptAttributeName; /* int, default 0
*/
APPKIT_EXTERN NSString *NSBackgroundColorAttributeName; /* NSColor, default
nil: no background */
APPKIT_EXTERN NSString *NSAttachmentAttributeName; /*
NSTextAttachment, default nil */
APPKIT_EXTERN NSString *NSLigatureAttributeName; /* int, default 1:
default ligatures, 0: no ligatures, 2: a\
ll ligatures */
APPKIT_EXTERN NSString *NSBaselineOffsetAttributeName; /* float, in
points; offset from baseline, default 0 */
APPKIT_EXTERN NSString *NSKernAttributeName; /* float, amount to
modify default kerning, if 0, kerning o\
ff */
APPKIT_EXTERN NSString *NSLinkAttributeName; /* ??? id
<NSTextLink>; link */


What's missing is some way of setting the strings alignment. That appears to
be set through the setAlignment:range: method.

Unfortunately, there appears to be no way to put an Alignment into a
dictionary. (It's not defined). So I have code that looks like this:

- (void)setColor:(NSColor *)aColor
{
[dict setObject:aColor forKey:NSForegroundColorAttributeName];
[text setAttributes:dict range:NSMakeRange(0,[text length])];
[text setAlignment:NSCenterTextAlignment range:NSMakeRange(0,[text
length])]; // bug in appkit
}

I think that this is pretty ugly. I'm sure that I can hard-code the correct
key for alignment, but I don't want to do that. I want to know what the
APPKIT_EXTERN is. Anybody know anything I don't?
_______________________________________________
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.


References: 
 >NSMutableAttributeString, fonts and alignment (From: "Simson Garfinkel" <email@hidden>)

  • Prev by Date: Re: Archiving objects without their owner[1]
  • Next by Date: Sketch's Save a Copy As... Items
  • Previous by thread: NSMutableAttributeString, fonts and alignment
  • Next by thread: Re: NSMutableAttributeString, fonts and alignment
  • Index(es):
    • Date
    • Thread