![](/img/trans.png)
[英]how can i write the code for iphone 3.5 inches screen and 4 inches screen
[英]how can i write the code for iphone 3.5 inches screen and 4 inches screen for ios6 & ios7
我正在开发一个应用程序。 在应用程序中,我为ios7&ios6的3.5英寸屏幕和4英寸屏幕编写了代码。 我带了一个视图控制器; 在此视图控制器中,我想显示两个图像,一个显示在顶部,另一个显示在底部。 在ios7 3.5英寸屏幕和4英寸屏幕上,显示器没有问题。 但是在4英寸屏幕和3.5英寸屏幕的ios6屏幕上,存在显示问题。 这两个图像显示不正确。 我不知道如何为4英寸和3.5英寸屏幕的ios6和ios7编写相同的代码。 任何人,请给我一些想法。 我是编程新手。 提前致谢。
下面是我的代码。
Viewcontroller.m(适用于ios7和ios6的3.5英寸和4英寸屏幕)。
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 65, 162, 57)];
imgLogo.image=[UIImage imageNamed:@"Logo-01.png"];
[self.view addSubview:imgLogo];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 415, 300, 153 )];
imgBuilding.image=[UIImage imageNamed:@"image-02.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];
}
else
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];
imgLogo.image=[UIImage imageNamed:@"Logo-01.png"];
[self.view addSubview:imgLogo];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];
imgBuilding.image=[UIImage imageNamed:@"image-02.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];
}
您必须检查os是IOS 7或更早版本,并取决于已设置的imageView。
UIImageView *imgLogo;
UIImageView *imgBuilding;
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 65, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 415, 300, 153 )];
}
else
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 45, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 395, 300, 153 )];
}
imgLogo.image=[UIImage imageNamed:@"icon.png"];
[self.view addSubview:imgLogo];
imgBuilding.image=[UIImage imageNamed:@"icon.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];
}
else
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];
}
else
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 50, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 325, 320,140 )];
}
imgLogo.image=[UIImage imageNamed:@"icon.png"];
[self.view addSubview:imgLogo];
imgBuilding.image=[UIImage imageNamed:@"icon.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];
}
希望这会帮助你。
你可以通过做autoResizing
又名“ 春和Struts”或利用最新的“ 自动布局 ”功能。
无论哪种方式,可以让你保持一个单一的厦门国际银行文件,而的位置和大小subViews
保持不变( 具体取决于您所设置它的方式 )
可以通过xib / storyboard以及以编程方式设置它们。
Springs和Struts是以前的方法,但仍然可用:
subView
的拉伸能力 链接:
自动布局要求您对约束的概念感到满意
这需要一点点努力,但嘿,如果苹果说更好,那肯定是 。
链接”
注意: 不能同时使用。 如果要使用Springs&Struts ,必须在视图上禁用自动布局功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.