Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

ios - How to make a uitableview in interface builder compatible with a 4 inch iPhone

How do I make a uitableview in interface builder compatible with 4 inch iphone5, and the older iPhone 4/4s?

There are three options in Xcode 4.5:

  • Freeform
  • Retina 3.5 full screen
  • Retina 4 full screen

If I chose Retina 4, then in the 3.5 inch phone it crosses/overflows the screen border

Using code, I can set the frame accordingly, but then what is the use of using interface builder?

How should one do it using Interface Builder?

EDIT

My question is for iphone 5 retina 4 inch screen. When inspecting the size of the view which has a status bar and navigation bar, here is the value of self.view.frame.size.height/width, frame 320.000000 x 416.000000 in case I choose freeform/none/retina 3.5

The autoresizing options are set so that the view expands in all directions, that is all struts and springs are enabled.

EDIT For testing in iOS6 simulator, If I set the following in code

self.tableView.frame    = CGRectMake(0, 0, 320, 546);
self.tableView.bounds   = CGRectMake(0, 0, 320, 546);
self.view.frame         = CGRectMake(0, 0, 320, 546);
self.view.bounds        = CGRectMake(0, 0, 320, 546);
NSLog(@"%2f - %2f", self.view.bounds.size.width, self.view.bounds.size.height);
NSLog(@"%2f - %2f", self.tableView.bounds.size.width, self.tableView.bounds.size.height);

I get the following output

 320.000000 - 546.000000
 320.000000 - 546.000000

And All the rows below the 480 px from the top are not selectable, as the 'view' still thinks they are out of bounds.

MY SOLUTION

Set the size to Retina 4 for all screens, even the main window xib file. It seems to work fine even on the iphone 4 after this. And all rows below 480px are now clickable in iOS 6 simulator

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

BEWARE of setting the size attribute to "Retina 4 Full Screen" if you present actionsheets in your application. This solution actually sets the dimensions of the main Window to the dimensions of the iPhone 5. In my case, setting this affected display in the iPhone 4 when you try to show an action sheet because it will try to show it from below the viewable screen.

The proper solution that works for all cases is to set the size to none and detect the screensize in the app delegate didfinishloading method and set the main window to that size or set the rootviewcontroller's view to that size. Actionsheets will work correctly.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height);

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...