Bronze Challenge: Draw an Image


#1

Hello everyone!

This is my approach to the Bronce Challenge. It’s kind of easy, but I would like to see another ways to achieve this.

UIImage *logoImage = [UIImage imageNamed:@"logo.png"];
CGRect imageFrame = CGRectMake(center.x - (logoImage.size.width / 2),
                               center.y - (logoImage.size.height / 2),
                               logoImage.size.width,
                               logoImage.size.height);
[logoImage drawInRect:imageFrame];

#2

How did you superimpose the image on top of the circles?


#3

I just draw the image after the circles using structured code logic, what comes first is at the bottom.


#4

Since the image was bigger than the screen size, I made the rect small by hand in order to reduce the image.

    UIImage *logoImage = [UIImage imageNamed:@"logo"];
    [logoImage drawInRect:CGRectMake(60, 134, 200, 300)];     // 320 X 568

And then I slightly modified it after referencing your code. Utilizing ‘center’ looks better.

    [logoImage drawInRect:CGRectMake(center.x - (center.x/2),
                                     center.y - (center.y/2),
                                     center.x,
                                     center.y)];

or

    [logoImage drawInRect:CGRectMake(bounds.size.width * 0.25,
                                     bounds.size.height * 0.25,
                                     bounds.size.width * 0.5,
                                     bounds.size.height * 0.5)];

#5

[code] UIImage *logoImage = [UIImage imageNamed:@“logo”];

CGRect rectOfThePic= CGRectMake(center.x - bounds.size.width / 4, center.y - bounds.size.height / 4, bounds.size.width / 2, bounds.size.height / 2);

[logoImage drawInRect:rectOfThePic];[/code]

#6

[code] UIImage *logoImage = [UIImage imageNamed:@“logo.png”];

CGRect imageRect = CGRectMake(center.x - logoImage.size.width / 4.0, center.y - logoImage.size.height / 4.0, logoImage.size.width / 2.0, logoImage.size.height / 2.0);


[logoImage drawInRect:imageRect];

[/code]


#7

Hi, can someone please help explain what I’m doing wrong. This seems like such a simple challenge but the image just won’t appear.

UIImage *logoImage = [UIImage imageNamed:@"logo.png"];
    CGRect imageFrame = CGRectMake(centre.x - (logoImage.size.width / 2.0),
                                   centre.y - (logoImage.size.height / 2.0),
                                   logoImage.size.width,
                                   logoImage.size.height);
    [logoImage drawInRect:imageFrame];

I’ve put the code after “[path stroke];” but even if I remove that I just get a blank screen. I’ve copied the logo into every folder to see if it was just in the wrong place but still nothing.


#8

This was my solution, to place it in the middle with adjustable scaling.

float scale = 0.5; [logoImage drawInRect:CGRectMake(center.x - (logoImage.size.width * scale)/2, center.y - (logoImage.size.height * scale)/2, logoImage.size.width * scale, logoImage.size.height * scale)];


#9

[quote=“danrussell”]Hi, can someone please help explain what I’m doing wrong. This seems like such a simple challenge but the image just won’t appear.

UIImage *logoImage = [UIImage imageNamed:@"logo.png"];
    CGRect imageFrame = CGRectMake(centre.x - (logoImage.size.width / 2.0),
                                   centre.y - (logoImage.size.height / 2.0),
                                   logoImage.size.width,
                                   logoImage.size.height);
    [logoImage drawInRect:imageFrame];

I’ve put the code after “[path stroke];” but even if I remove that I just get a blank screen. I’ve copied the logo into every folder to see if it was just in the wrong place but still nothing.[/quote]

danrussell - I’m not sure if you got this figured out, but I too was having the same problem. I found a solution through stackoverflow http://stackoverflow.com/questions/12463445/uiimage-imagenamed-does-not-display-the-image-with-xcode-4-4
You have to add the image to the target of the program. Once I did this, the image showed up just fine. Hope this helps