2011-06-03 47 views
0

行,所以我有这样的代码,它可以让我把一个背景图像:如何使用CGRectMake大小背景

我很想知道如何大小这一点,所以在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); 

其中一期工程,但问题是它的背后看法,所以我不能看到它。我可以清楚地看到视图,但它上面有需要显示的对象。

任何帮助将是最赞成的

+0

[self.view sendSubviewToBack:streamBG];应该是[self.view sendSubviewToBack:image]; – 2011-06-03 11:37:56

回答

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设置到所需的位置。

希望它有帮助。

0

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

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