Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
I know CATextLayer has methods for setting font and fontsize, but not for every attribution e.g. linethrough or underline. So, I am trying to set an NSAttributedString to the string property of CATextLayer.

The documentation of CATextLayer states at the beginning:
The CATextLayer provides simple text layout and rendering of plain or attributed strings. The first line is aligned to the top of the layer.
and in the discussion of the string property:
The text must be an instance of NSString or NSAttributedString. Defaults to nil.

Based on this, using NSAttributedStrings should be fine. Unfortunately, the code snippet gives "-[NSConcreteAttributedString _isCString]: unrecognized selector sent to instance". Is there another way I am supposed to create the NSAttributedString?

Code:
NSFont *font = [NSFont fontWithName:@"Palatino-Roman" size:14.0];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font
                                                                                   forKey:NSFontAttributeName];

NSAttributedString *attrString = [[[NSAttributedString alloc] initWithString:@"strigil"
                                                                                        attributes:attrsDictionary] autorelease];
CATextLayer *textlayer = ...//obtain layer
textlayer.string = @"aString"; //works
textlayer.string = attrString; //does not work
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
There's nothing wrong with the posted code. I copied and pasted it into the CALayerEssentials sample code and it worked as expected without log messages.
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
There's nothing wrong with the posted code. I copied and pasted it into the CALayerEssentials sample code and it worked as expected without log messages.

Oh, that is strange. I will (also) start a new project and see if it works.
Thanks for the reply.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.