[英]how can i write the code for iphone 3.5 inches screen and 4 inches screen for ios6 & ios7
I am developing an app. 我正在开发一个应用程序。 In the app I wrote the code for a 3.5-inches screen and 4-inches screen for ios7&ios6.
在应用程序中,我为ios7&ios6的3.5英寸屏幕和4英寸屏幕编写了代码。 I took one view controller;
我带了一个视图控制器; in this view controller I want to display two images, one for the top and another for the bottom.
在此视图控制器中,我想显示两个图像,一个显示在顶部,另一个显示在底部。 On the ios7 3.5-inch screen and 4 inches screen there is no problem with the display.
在ios7 3.5英寸屏幕和4英寸屏幕上,显示器没有问题。 But on the ios6 screen for 4-inches screen and 3.5 inches screen, there is a display problem.
但是在4英寸屏幕和3.5英寸屏幕的ios6屏幕上,存在显示问题。 The two images are not displayed properly.
这两个图像显示不正确。 I don't know how to write the same code for both the ios6 and ios7 for 4-inches& 3.5 inches screen.
我不知道如何为4英寸和3.5英寸屏幕的ios6和ios7编写相同的代码。 Please give me ideas, anyone.
任何人,请给我一些想法。 I am new to programming.
我是编程新手。 Thanks in advance.
提前致谢。
The below is my code. 下面是我的代码。
Viewcontroller.m (3.5 inches and 4-inches screen for ios7 & ios6). 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];
}
You have to check whether os is IOS 7 or Earlier and depending upon that you have set your imageView. 您必须检查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];
}
Hope this will help you. 希望这会帮助你。
You can do this via autoResizing
aka ' Spring and Struts ' or by utilizing the latest ' Autolayout ' feature. 你可以通过做
autoResizing
又名“ 春和Struts”或利用最新的“ 自动布局 ”功能。
Either way allows you to maintain a single xib file while the positioning and sizing of the subViews
remains the same ( depending on the way you have set it up ) 无论哪种方式,可以让你保持一个单一的厦门国际银行文件,而的位置和大小
subViews
保持不变( 具体取决于您所设置它的方式 )
They can be set up via xib/storyboard as well as programmatically. 可以通过xib / storyboard以及以编程方式设置它们。
Springs and Struts was the previous method but it's still available: Springs和Struts是以前的方法,但仍然可用:
subView
subView
的拉伸能力 Links: 链接:
Autolayout requires you to be comfortable with the concept of constraints 自动布局要求您对约束的概念感到满意
It's a tad bit more effort but hey, if apple says it's better, it sure is . 这需要一点点努力,但嘿,如果苹果说更好,那肯定是 。
Links" 链接”
NOTE: You can't use both together. 注意: 不能同时使用。 You have to disable Autolayout feature on the view if you want to use Springs & Struts
如果要使用Springs&Struts ,必须在视图上禁用自动布局功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.