I'm just getting into iOS development. I'm tinkering with core graphics, and I'm trying to figure out how to both limit the size of a drawing, and place it at specific coordinates on the screen. Here is my HomeViewController.m loadView AND addCircle method, and my Artist.m drawRect method:
HomeViewController.m -> loadView
- (void)loadView
{
NSLog(@"HomeViewController.m : loadView");
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UILabel *lbl;
lbl = [[UILabel alloc] initWithFrame:CGRectMake(65, 50, 220, 70)];
lbl.text = @"Home Screen";
lbl.font = [UIFont boldSystemFontOfSize:30];
[self.view addSubview:lbl];
[lbl release];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark ];
infoButton.frame = CGRectMake(10, 10, 300, 300);
[self.view addSubview:infoButton];
[infoButton addTarget:self action:@selector(loadInfo) forControlEvents:UIControlEventTouchUpInside];
[infoButton release];
[self addCircle];
// self.view = [[[Artist alloc] init] autorelease];
}
HomeViewController.m -> addCircle
- (void)addCircle
{
Artist *artist = [[[Artist alloc] init] autorelease];
[self.view addSubview:artist];
// [artist drawRect:CGRectMake(100, 100, 100, 100)];
}
Artist.m -> drawRect
- (void)drawRect:(CGRect)rect
{
NSLog(@"Artist.m : drawRect");
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef red = [[UIColor redColor] CGColor];
CGContextFillRect(context, CGRectMake(130,200,120,120));
CGContextSetFillColorWithColor(context,red);
CGContextFillEllipseInRect(context, CGRectMake(130, 200, 120, 120));
}
Essentially, I'm trying to avoid having the drawing take up the whole screen, but rather be limited to the size that I make it and sit on top of the other views.
NSLog(@"%s", __func__);
will log the name of the current function or the signature of the current method. - Peter Hoseyself.view
. You own it through theview
property, and you also own it because you created it, so it is owned twice. If you never release that creation ownership, you will leak it. Conversely, because you didn't create the UIButton withalloc
, you don't own that and should not release it. For further information, see the Memory Management Programming Guide: developer.apple.com/library/ios/documentation/Cocoa/Conceptual/… - Peter Hosey