Graphics Programs Reference
In-Depth Information
CGPoint center;
center.x = bounds.origin.x + bounds.size.width / 2.0;
center.y = bounds.origin.y + bounds.size.height / 2.0;
float maxRadius = hypot(bounds.size.width, bounds.size.height) / 4.0;
float maxRadius = hypot(bounds.size.width, bounds.size.height) / 2.0;
CGContextSetLineWidth(ctx, 10);
CGContextSetRGBStrokeColor(ctx, 0.6, 0.6, 0.6, 1.0);
CGContextAddArc(ctx, center.x, center.y, maxRadius, 0.0, M_PI * 2.0, YES);
CGContextStrokePath(ctx);
// Draw concentric circles from the outside in
for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20) {
// Add a path to the context
CGContextAddArc(ctx, center.x, center.y,
currentRadius, 0.0, M_PI * 2.0, YES);
// Perform drawing instruction; removes path
CGContextStrokePath(ctx);
}
}
Build and run the application again. This time, each HypnosisView draws a number of
circles.
That is one ugly screen; let's get rid of one of the instances of HypnosisView and make
the remaining one the size of the screen. In HypnosisterAppDelegate.m , modify
application:didFinishLaunchingWithOptions: .
CGRect viewFrame = CGRectMake(160, 240, 100, 150);
HypnosisView *view = [[HypnosisView alloc] initWithFrame:viewFrame];
HypnosisView *view = [[HypnosisView alloc] initWithFrame:[[self window]
bounds]];
[[self window] addSubview:view];
CGRect anotherFrame = CGRectMake(20, 30, 50, 50);
HypnosisView *anotherView = [[HypnosisView alloc] initWithFrame:anotherFrame];
[view addSubview:anotherView];
Build and run the application. Now you have a single instance of HypnosisView that
fills the entire screen. Much better.
There are Core Graphics functions to draw most anything you like. Check the documenta-
tion for functions and types beginning with CG .
 
Search WWH ::




Custom Search