tags:

views:

298

answers:

3

Hi,

I need to draw a .png image on an UIView. I have no clue how to do this. Is there any way to do this instead of using UIImageView. Please guide me.

A: 

well, you can read up on CGImage if you want to, but really the simplest thing is to just add a UIImageView as a subview of your current view.

You can also use OpenGL if you're doing something more complicated, of course.

David Maymudes
thanks for helping me
saikamesh
+1  A: 

You question is a bit too vague. Where in your application do you want to render the image? You have a lot of options to get the image to the screen. You can override the title text on a Navigation Controller NavBar with an image, you can set an image as a background on a given view etc...

I would need to know two things to actually answer this question.

1) Why do you not want to use UIImageView? It is perfectly suited to rendering the image.

2) What is the goal of getting the image on the screen? What function or use is it serving?

MystikSpiral
I need to add a view on top of an image, The view I need to add on top of the image has some more views on it which are used for displaying some text
saikamesh
In some other page, I need to add an image(background image) on a view on top of the image I need to add a text and a small image. The view has to receive touch event also
saikamesh
One more thing which is not related to this question. I need to learn quartz 2d drawing, but I dont know where to start. Where can I read about the basics and get some example programs
saikamesh
+4  A: 

You can use the drawAtPoint or drawInRect methods of UIImage.

For example, you can subclass UIView (I'm actually assuming you already have), and use this code inside drawRect:

- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed:@"foo.png"];

    [image drawAtPoint:CGPointMake(0,0)];
    /* or */
    [image drawInRect:rect];
    /* or */
    [image drawInRect:CGRectMake(0,0,100,100)];
}

For more methods (alpha transparency, patterns), please see the UIImage Class Reference.

Can Berk Güder
This works fine. But in some other place, I need to have an image as a background image of a view(baseview). On top of it I need to add one other view which is used for displaying some text, and one small image also needs to be added on the baseview, small image is dynamic, some times it doesnt need to be added
saikamesh
any drawing you do after this will be done on top of the first image.so for example, you can draw the text on top of this image, and draw the second image wherever you want. similar methods (drawInRect, drawAtPoint, etc.) exist for NSStrings.
Can Berk Güder
Thanks a lot !!!
saikamesh