简体   繁体   English

我如何编写适用于iOS 6和iOS 7的iPhone 3.5英寸屏幕和4英寸屏幕的代码

[英]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是以前的方法,但仍然可用:

  • Spring is the stretching ability of the subView 弹簧subView的拉伸能力
  • Strut is the placement or you can say, the hugging ability. 支撑是放置能力,或者可以说是拥抱能力。 (ie it hugs the top bound or the bottom bound or left or right) (即,它拥抱上界或下界或左或右)

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.

相关问题 我怎样才能为iphone 3.5英寸屏幕和4英寸屏幕编写代码 - how can i write the code for iphone 3.5 inches screen and 4 inches screen 如何为iOS7 3.5英寸和4英寸屏幕的UITableview设置背景图像 - How to set the Background image for UITableview for ios7 3.5 inches and 4-inches screen 我如何为iphone3.5和iphone 4英寸屏幕(ios6和ios7)设计Single xib? - How can i design Single xib for iphone3.5,and iphone 4 inch screen (ios6 and ios7)? 如何在ios6和ios7中为4英寸屏幕和3.5英寸屏幕显示UIButton和UITableview - how to display the UIButton and UITableview in ios6&ios7 for 4-inches screen and 3.5 inches screen 如何使用一个故事板用于带有自动布局(ios6 + ios7)的4英寸和3.5英寸iphone屏幕? - how can I use one storyboard for 4“ and 3.5” iphone screens with autolayout (ios6 + ios7)? 在3,5英寸屏幕iOS上UIScrollView内部的UIView不能调整大小 - UIView inside UIScrollView not resizing on 3,5 inches screen iOS 在iOS Simulator 4和3.5英寸中加载新闻 - Loading news in both iOS Simulator 4 and 3.5 inches 获取 iPhone 的物理屏幕尺寸(以英寸为单位) - Getting the physical screen size in inches for iPhone 模拟器中iOS6和iOS7的显示屏幕不同 - Display screen for iOS6 and iOS7 in simulator is different 3.5英寸iPhone不支持XIB - XIB not supported for iphone of 3.5 inches
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM