如何使用CGRectMake来调整背景大小

时间:2011-06-03 11:35:48

标签: iphone

好的所以我有这个代码,它允许我把背景图像放在:

我很想知道如何调整尺寸,因此在iPhone 4上我可以获得320x480的尺寸,但是使用570.855的图像可以很好。

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_stream-570x855.jpg"]];

我试过这个:

UIImageView *image = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"background_stream-570x855.jpg"]];

[self.view sendSubviewToBack:streamBG];

image.frame = CGRectMake(0, 0, 320, 480);

哪个有效,但问题是它在视图后面,所以我看不到它。我可以使视图清晰,但它上面有需要显示的对象。

任何帮助都是最好的

2 个答案:

答案 0 :(得分:0)

将视图放在所需位置有多种选择。

 [self.view sendSubviewToBack:streamBG]; //Sends subview to last position i.e. at the last
 [self.view bringSubviewToFront:streamBG] //Brings subview to first position i.e. at the first.
 [self.view insertSubview:streamBG atIndex:yourDesiredIndex];//Put at desired index.

这不是您的问题的答案,但它可以帮助您将您的imageview设置到所需的位置。

希望它有所帮助。

答案 1 :(得分:0)

回答有关尺寸调整的部分问题。如果你想要视网膜显示器(iPhone4)的全分辨率,你需要为你的应用程序使用2个不同的图像你应该为旧版iPhone提供320x480图像(即myImage.png),为iPhone提供分辨率为640x960的一个图像(640x960) 4.对高分辨率版本使用完全相同的名称,但在末尾添加“@ 2x”(即myImage@2x.png)。在您的代码中,您必须调用的是基本名称(即myImage.png),应用程序将根据其运行的硬件选择正确的图像。这将为您提供最佳的应用体验。

关于背景视图可见性的另一部分,您可以在阻止它的视图上清除背景颜色([UIColor clearColor])。这会使内容在该视图中可见,但视图的自我将是清晰的。或者,您可以将背景插入@Jennis建议的特定索引,而不是将其强制到后面。