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?
I've been checking aspect ratio. Not as general as some of the other methods but still more flexible for future devices than checking a specific resolution.
From your question ,it seems you want to correct UI depending on device and resolution. In that case, it is fine and you can use below given code to identify the device. But for non UI things, like looking for a device capability which is present in one device, absent in other, It is always advised to check for whether that capability is present, rather than which is the device model. From apple's official forum. (login required)
You should really use the autolayout features to make your views adapt to whatever format the screen is.
However, if you only want to know if the device is an iPhone 5 (ie has 1136px in height) you could use:
Could ofcourse be turned into a macro.
I dont have iphone 5 but on the other phone this code worked great:
Remember to import:
define this macro in some constant.h file and use it any where to check