drawing different quartz 2d
Posted
by Cosizzle
on Stack Overflow
See other posts from Stack Overflow
or by Cosizzle
Published on 2010-03-08T18:46:17Z
Indexed on
2010/03/08
18:51 UTC
Read the original article
Hit count: 587
Hello,
I'm trying to make a small application or demo thats a tab bar application. Each bar item loads in a new view. I've created a quartzView class that is called on by the controller:
- (void)viewDidLoad {
quartzView *drawingView = [[quartzView alloc] initWithFrame:CGRectMake(0,0,320,480)];
[self.view addSubview:drawingView];
[super viewDidLoad];
}
From my understanding, the drawRect method must be triggered in order to render the object and to draw it. This is my quartzView class:
#import "quartzView.h"
@implementation quartzView
#pragma mark shapes
// Blue Circle
- (void)drawRect:(CGRect)rect
{
NSLog(@"Trying to draw...");
CGContextRef ctx = UIGraphicsGetCurrentContext(); //get the current context
CGContextClearRect(ctx, rect); //clear off the screen
//draw a red square
CGContextSetRGBFillColor(ctx, 255, 0, 0, 1);
CGContextFillRect(ctx, CGRectMake(10, 10, 50, 50));
}
// ====================================================================================================
#pragma mark -
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)dealloc {
[super dealloc];
}
@end
So how would I go about to say,
- if the view is view one, draw a square
- if it's view two draw a circle.
And so on.
© Stack Overflow or respective owner