使用UIImageView的图像层

Tai*_*mal 2 iphone objective-c uiimageview uiimage

我只是想确认一下,我们是否有可能使用UImageView添加图像层,一个作为背景,另一个作为背景.我的意思是我想要使用2个图像,一个必须在背景中,另一个在它上面.(这两幅图像的尺寸均为320 x 480).

通过属性检查器,我们无法做到.有没有我们可以通过代码来做到这一点.也许使用子视图或其他东西.

dra*_*ard 8

每个图像需要一个UIImageView,但只要顶视图不是不透明的,它们就会显示为分层.如果要将它们视为单个实体,可以将两个图像视图放入第三个UIView中.

编辑:

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.
Run Code Online (Sandbox Code Playgroud)

imageLayered现在是一个带有背景和前景图像的UIView.