• 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
Superscript attribute with CATextLayer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Superscript attribute with CATextLayer


  • Subject: Superscript attribute with CATextLayer
  • From: "Stephan Michels" <email@hidden>
  • Date: Mon, 20 Oct 2008 09:08:57 +0200

Hi,
I have the problem if I use super/subscript within an attributed string, then
it doesn't seems to work with CATextLayer, and I don't know why.

I tried NSSuperscriptAttributeName and NSBaselineOffsetAttributeName

  string = [[NSMutableAttributedString alloc] init];
  [string beginEditing];
  [string replaceCharactersInRange:NSMakeRange(0,0) withString:@"CO2"];
  [string addAttribute:NSFontAttributeName value:[NSFont
controlContentFontOfSize:12] range:NSMakeRange(0,3)];
  [string addAttribute:NSForegroundColorAttributeName value:[NSColor
blackColor] range:NSMakeRange(0,3)];

  [string addAttribute:NSUnderlineStyleAttributeName value:[NSNumber
numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0,2)];

  // first case
  [string addAttribute:NSSuperscriptAttributeName value:[NSNumber
numberWithInt:-1] range:NSMakeRange(2,1)];
  // second case
  //[string addAttribute:NSBaselineOffsetAttributeName value:[NSNumber
numberWithInt:-5] range:NSMakeRange(2,1)];
  // third case
  //[string subscriptRange:NSMakeRange(2, 1)];

  [string endEditing];

It works perfectly with drawAtPoint:

- (void)drawRect:(NSRect)rect {
	[string drawAtPoint:NSMakePoint(10, 20)];
}

But not with a CATextLayer

- (void)awakeFromNib {
	self.wantsLayer = YES;

	layer = [CATextLayer layer];
	layer.string = string;
	layer.bounds = CGRectMake(0, 0, layer.preferredFrameSize.width,
layer.preferredFrameSize.height);
	layer.position = CGPointMake(10, 150);
	layer.borderWidth = 1;
	layer.anchorPoint = CGPointMake(0,0);

	[self.layer addSublayer:layer];
}

Does anyone know how to solve it or have an explanation why it doesn't work?

Thank you,
Stephan Michels.
_______________________________________________

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

  • Prev by Date: Re: Mutable arrays
  • Next by Date: [ANN] InputMethodKit backporting component for OS X 10.4 Tiger
  • Previous by thread: Detecting system preference for trackpad zooming.
  • Next by thread: Re: Superscript attribute with CATextLayer
  • Index(es):
    • Date
    • Thread