检测硬件类型,iPhone4或iPhone5的最佳方法? [英] Best way to detect hardware type, iPhone4 or iPhone5?

查看:101
本文介绍了检测硬件类型,iPhone4或iPhone5的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置一个应用程序,其中我想根据正在使用的iPhone的类型对视图布局进行多个更改。具体来说,我想知道垂直屏幕分辨率是 1136 (iPhone5)还是 960 (iPhone4)。我想做的事情之一是调整UITableViewCell在UITableView的高度,以便在任何手机上运行应用程序时,不显示部分单元格。

I am setting up an application where I want to make a number of changes to the view layout based on the type of iPhone in use. Specifically I want to know if the vertical screen resolution is 1136 (iPhone5) or 960 (iPhone4). One of the things I want to do is adjust the height of my UITableViewCells in a UITableView so that no partial cells are displayed when the app is run on either phone.

我的问题是:什么是检测正在使用的手机硬件类型的最佳方式,以便我可以对我的视图布局进行适当的更改?

My question is: what is the best way to detect the phone hardware type in use so that I can make the appropriate changes to my view layout?

推荐答案

您应该真正使用autolayout功能,使您的视图适应屏幕上的任何格式。

You should really use the autolayout features to make your views adapt to whatever format the screen is.

想知道设备是否是iPhone 5(即高度为1136px),您可以使用:

However, if you only want to know if the device is an iPhone 5 (ie has 1136px in height) you could use:

[ [ UIScreen mainScreen ] bounds ].size.height

当然可以变成一个宏。

这篇关于检测硬件类型,iPhone4或iPhone5的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆