0

当我使用此代码在 xcode 中创建图像视图时:

UIImageView *img = [[UIImageView alloc] initWithImage:@"image.png"];

img.frame = CGRectMake(40, 40, 80, 80);
img.alpha = 0.25;
[self.view addSubview:img];

它将在视图中生成图像,但是如果我喜欢说我使用 IB 添加的屏幕上的 5 个按钮,并且我希望我在 xcode 中创建的图像位于按钮后面,我该怎么办?

是否有一行代码可以将图像设置在后面?

提前致谢 :)

4

2 回答 2

2
[self.view sendSubviewToBack:img];
于 2012-08-01T15:29:08.603 回答
1

正如@Noah 所述,您可以使用:

[self.view sendSubviewToBack:img];

只需将您的视图发送到后面。您还可以使用以下内容进行更高级的配置。

[self.view insertSubview:img aboveSubview:otherSubView];
[self.view insertSubview:img belowSubview:otherSubView];
[self.view insertSubview:img atIndex:MYINDEXPATH];
[self.view exchangeSubviewAtIndex:MYINDEXPATH withSubviewAtIndex:ANOTHERINDEXPATH];

可以在UIView 类参考中找到详细信息。

于 2012-08-01T18:14:46.783 回答