Iphone 使用启动图像作为ViewController背景图像
我创建了3个启动映像(默认值Default@2x违约-568@2x)在其适当的决议中。我想使用这些图像作为初始视图控制器的背景图像 然而,当我设计我的启动图像时,我考虑到了状态栏,并将该区域留空。当我尝试使用下面的代码将视图控制器的背景图像设置为启动映像时,我的启动映像从我的状态栏底部开始,空白区域是可见的。基本上,我的640x1136发射图像被压缩到640x1096空间。做我正在尝试的事情的正确方法是什么Iphone 使用启动图像作为ViewController背景图像,iphone,ios,ios6,Iphone,Ios,Ios6,我创建了3个启动映像(默认值Default@2x违约-568@2x)在其适当的决议中。我想使用这些图像作为初始视图控制器的背景图像 然而,当我设计我的启动图像时,我考虑到了状态栏,并将该区域留空。当我尝试使用下面的代码将视图控制器的背景图像设置为启动映像时,我的启动映像从我的状态栏底部开始,空白区域是可见的。基本上,我的640x1136发射图像被压缩到640x1096空间。做我正在尝试的事情的正确方法是什么 UIImage *backgroundImage = [[UIImage allo
UIImage *backgroundImage = [[UIImage alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568) {
backgroundImage = [UIImage imageNamed:@"Default-568h@2x"];
}
else{
backgroundImage = [UIImage imageNamed:@"Default"];
}
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
[backgroundImageView setFrame:[[self view] bounds]];
[[self view] addSubview:backgroundImageView];
更新:
我替换了:
[backgroundImageView setFrame:[[self view] bounds]];
与:
现在它的表现似乎正符合我的要求。试试这个:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];
另外,尽量不要以编程方式设置backgroundImageView的框架。它应该已经是调用initWithImage:
时的大小,请尝试以下操作:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];
另外,尽量不要以编程方式设置backgroundImageView的框架。当你调用<代码> iNITE时,它应该已经是一个大小:图像:< /C> > < P>使用未包含空白区域的未编辑的图像。这很好用 选中替换此
[backgroundImageView设置框架:[[self-view]边界]]代码>使用以下代码
int statusBarHeight = statusBar.frame.size.height;
backgroundImageView.frame = CGRectMake(0 ,statusBarHeight,self.view.frame.size.width , self.view.frame.size.height-statusBarHeight);
使用未包含空白区域的未编辑图像。这很好用
选中替换此[backgroundImageView设置框架:[[self-view]边界]]代码>使用以下代码
int statusBarHeight = statusBar.frame.size.height;
backgroundImageView.frame = CGRectMake(0 ,statusBarHeight,self.view.frame.size.width , self.view.frame.size.height-statusBarHeight);
从图像中删除空白区域..等等,图像文件中有空白区域吗?喜欢部分像素吗?是的,最上面的20/40px是黑色的。如果我从图像中删除空白区域,当应用程序启动时,状态栏覆盖图像的一部分。从图像中删除区域空白。等等,您的图像文件中有一个空白区域吗?喜欢部分像素吗?是的,最上面的20/40px是黑色的。如果我从图像中删除空白区域,当应用程序启动时,状态栏会覆盖图像的一部分。当我尝试这个图片时,我的图像在被切断时根本不会缩小。它仍然会在状态栏下方留下间隙吗?不知道您在试图隐藏的图像本身上有一个黑色的位。在这种情况下,尝试将中心移动20个点:backgroundImageView.center=CGPointMake(backgroundImageView.x,backgroundImageView.y-20)代码>当我尝试此操作时,我的图像根本没有缩小。它是否仍在状态栏下方留有间隙?不知道您试图隐藏的图像上有黑色部分。在这种情况下,尝试将中心移动20个点:backgroundImageView.center=CGPointMake(backgroundImageView.x,backgroundImageView.y-20)代码>我在工作中得到了类似的东西:[backgroundImageView setFrame:CGRectMake(0,-20,self.view.frame.size.width,self.view.frame.size.height+20)];我想你是用空白区域编辑的图像啊?上面的代码对于没有空白区域的图像应该可以很好地工作。我得到了类似的东西来工作:[backgroundImageView setFrame:CGRectMake(0,-20,self.view.frame.size.width,self.view.frame.size.height+20)];我想你是用空白区域编辑的图像啊?上面的代码对于没有空白区域的图像来说效果很好。