Same xib for iPhone4 and iPhone5 possible?

2019-01-13 04:35发布

Is there any way I can design my classes for both iPhone4 and iPhone5 using the same xib?

标签: xib iphone-5
8条回答
姐就是有狂的资本
2楼-- · 2019-01-13 05:18

Add a image named Default-568h@2x.png. That will identify your app as one that supports iPhone 5 metrics. And also you need to do auto sizing of your views properly.

enter image description here

查看更多
戒情不戒烟
3楼-- · 2019-01-13 05:24

Well short answer to you question is YES;

Long is :- If you user XCode 4.5 and build app that is universal the NIB files and Classes would work perfectly for Iphone 4 and Iphone 5; Understand for you it important to know the version of SDK of these mobiles not the mobile version them self.

Another thing is that iphone 5 size is little bigger then iphone 4 so you need to design accordingly.. please read my answer at Iphone 5 screen resolution issue for better understanding.

Also look at the How to develop or migrate apps for iPhone 5 screen resolution? answer for more clarification on universal app desing.

查看更多
Anthone
4楼-- · 2019-01-13 05:30

Yes, you can use the same XIB to design for iPhone 4 and iPhone 5 by using Auto-Layout.

Build an app using iOS 6 as the Base SDK and use the Auto Layout feature to make screens that can scale for all type of screens. You'll need Xcode 4.5 to do this.

Get started with Auto Layout here:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2

查看更多
干净又极端
5楼-- · 2019-01-13 05:30

Please define below line and check condition based on device.

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

if (IS_IPHONE_5) {

        btnBookmark.frame=CGRectMake(0, 460, 100, 70);
        btnBookmark.frame=CGRectMake(150, 460, 100, 70);


    }else{
        btnBookmark.frame=CGRectMake(0, 360, 100, 70);
        btnBookmark.frame=CGRectMake(150, 360, 100, 70);


    }
查看更多
何必那么认真
6楼-- · 2019-01-13 05:34

If you want to make some small changes(e.g images position and sizes, scroll view content insets..), you can use codes to differentiate between iPhone 5 and iPhone 4/4s, and implement your codes inside the if/else statement.

Use this:

https://stackoverflow.com/a/12447113/1371949

to detect the iPhone type.

查看更多
Root(大扎)
7楼-- · 2019-01-13 05:34

Use AutoAutoresizing so that u can make app compatible with both iOS 5 and iOS 6. This is easy if your layout is having minimum dependancies. And this is possible for fixing issues with components like UIToolBar. Buttons in iPhone 5.

查看更多
登录 后发表回答