views:

139

answers:

1

Hi everyone,

I just wanted to confirm, is it possible that we add layers of images using UImageView, one as background and other on top of it. I mean i want to use 2 images one has to be in the background and the other on top of it. ( the size of both these images is 320 x 480 ).

Through the attributes inspector we cant do it. Is there any we can do it through code. Maybe using subview or something. Thanks Geeks :)

Taimur Ajmal

A: 

You need one UIImageView for each image, but they will appear layered as long as the top view is not opaque. You could put both image views into a third UIView if you want to treat them as a single entity.

Edit:

imageBackground = [[UIImageView alloc] initWithImage:[UIImageNamed:@"background.png"]];
imageForeground = [[UIImageView alloc] initWithImage:[UIImageNamed:@"foreground.png"]];
imageLayered = [[UIView alloc] initWithFrame:[imageBackground frame];

[imageLayered addSubview:imageBackground];
[imageLayered addSubview:imageForeground];

// release all views at some point.

imageLayered is now a UIView with a background and foreground image.

drawnonward
Thnx @drawnonward . I got ur point partially . I need one UImageView for each image , Fine i ll do it. Then how can i put them in layers so that they can be viewed as one in the background and other on top of it.
T. A.
@drawnonward I just wanted to confirm. Instead of imageLayered shall i have to used self.view ?or i must add another view, say 'imageLayered' and connect it. After tht 2 layers of image wud be displayed
T. A.
Yes, you can use self.view instead of imageLayered.
drawnonward