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.
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.
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.
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?
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.