1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
- (void)drawRect:(NSRect)aRect
{
   NSEraseRect(aRect);

   NSFont*   font       = [NSFont controlContentFontOfSize:[NSFont systemFontSize]];
   NSColor*  foreground = [NSColor blackColor];
   NSColor*  background = [NSColor blueColor];
   NSNumber* underline  = [NSNumber numberWithInt:NSUnderlineStyleSingle];

   NSAttributedString* str = [[[NSAttributedString alloc] initWithString:@"Lorem ipsum dolor sit amet, consectetur adipisicing elit." attributes:
      [NSDictionary dictionaryWithObjectsAndKeys:
         font,       NSFontAttributeName,
         foreground, NSForegroundColorAttributeName,
         background, NSBackgroundColorAttributeName,
         underline,  NSUnderlineStyleAttributeName,
      nil]] autorelease];

   CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
   CGContextSetTextMatrix(context, CGAffineTransformMake(1, 0, 0, [self isFlipped] ? -1 : 1, 0, 0));

   CGContextSetTextPosition(context, 10.0, 30.0);

   CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)str);
   CTLineDraw(line, context);
   CFRelease(line);
}