Best way to manage screen height differences on iPhone 5 and others

断了今生、忘了曾经 提交于 2019-12-10 10:57:46

问题


What is the best way to manage screen height differences between iPhone 5 and other versions?

If we use the storyboard or xib it will resize it accordingly. But if the whole view is build programmatically, how we take care of this issue.

Currently what I do is that I get the whole screen height and set the rest of the UI elements according to this height like height * .7 or height *.5 ..

But still it didn’t give me the best experience.

Thanks,


回答1:


You can check for [UIScreen mainScreen].bounds.size.height(may be, use it as a static method or do a #define) and do the screen design based on the screen height. Another way is to use the view.autoresizingMask property to adjust the views.

for eg:-

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

If you are building for iOS 6, you can use Auto layout features.




回答2:


In your viewDidLoad just check for screen size Like this...

- (void)viewDidLoad
{
   [super viewDidLoad];
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
   if (screenBounds.size.height == 568)
   {
       //iPhone 5
   }
   else
   {
       // iPhone 4
   }

}


来源:https://stackoverflow.com/questions/13689895/best-way-to-manage-screen-height-differences-on-iphone-5-and-others

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!