One Quickie


Drawing outlined / filled text (Graphics->General)
I wanted to draw text like this:

- (void) drawRect: (CGRect) rect {
    NSString *string = @"132";

    CGContextRef ctx = UIGraphicsGetCurrentContext ();

    CGContextTranslateCTM (ctx, 0.0, self.bounds.size.height);
    CGContextScaleCTM (ctx, 1.0, -1.0);

    CGContextSelectFont (ctx, "Helvetica-Bold", 48.0, kCGEncodingMacRoman);
    CGContextSetTextDrawingMode (ctx, kCGTextFillStroke);

    // Draw a background to see the text on.
    CGContextSetFillColorWithColor (ctx, [[UIColor yellowColor] CGColor]);
    CGContextFillRect (ctx, self.bounds);

    CGContextSetFillColorWithColor (ctx, [[UIColor blackColor] CGColor]);
    CGContextSetStrokeColorWithColor (ctx, [[UIColor whiteColor] CGColor]);

    CGContextSetLineWidth (ctx, 2);
    CGContextSetShadow (ctx, CGSizeMake (3.0, 3.0), 2.5);
    CGContextShowTextAtPoint (ctx, 50, 50, [string UTF8String], string.length);

} // drawRect
(Thanks to Chris Liscio for handy pointers)



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com