Note that there are some explanatory texts on larger screens.

plurals
  1. POcore graphics drawRect specify coordinates
    text
    copied!<p>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:</p> <p>HomeViewController.m -> loadView</p> <pre><code>- (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]; } </code></pre> <p>HomeViewController.m -> addCircle</p> <pre><code>- (void)addCircle { Artist *artist = [[[Artist alloc] init] autorelease]; [self.view addSubview:artist]; // [artist drawRect:CGRectMake(100, 100, 100, 100)]; } </code></pre> <p>Artist.m -> drawRect</p> <pre><code>- (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)); } </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload