Graphics Programs Reference
In-Depth Information
// Draw the string
[text drawInRect:textRect
withFont:font];
}
Let's spice it up with a shadow. Add the following code in
HypnosisView.m
.
[[UIColor blackColor] setFill];
// The shadow will move 4 points to the right and 3 points down from the text
CGSize offset = CGSizeMake(4, 3);
// The shadow will be dark gray in color
CGColorRef color = [[UIColor darkGrayColor] CGColor];
// Set the shadow of the context with these parameters,
// all subsequent drawing will be shadowed
CGContextSetShadowWithColor(ctx, offset, 2.0, color);
// Draw the string
[text drawInRect:textRect
withFont:font];
Build and run the application. You now have shadow.
UIColor
's
setStroke
method replaces
CGContextSetRGBStrokeColor
, but it
is a one-to-one line replacement, so it doesn't save that much work.
NSString
's
drawInRect:withFont:
, on the other hand, buys you a lot of convenience.
UIImage
has a similar useful method,
drawInRect:
, for drawing an image object to a
context.