Obtaining screen resolution is a very useful function. In some game-related development, drawing and screen resolution are inseparable. Obtaining the resolution of the current screen is essential.
Two steps are allowed to obtain the screen resolution.
1. Obtain the size of the current screen:
Cgrect rect_screen = [[uiscreenmainscreen] bounds];
Cgsize size_screen = rect_screen.size;
2. Obtain scale:
Cgfloat scale_screen = [uiscreen mainscreen]. scale;
At this time, the product of the width and height of the screen size and the scale is the corresponding resolution value.
It is worth noting that I have read some code to obtain the device type first and then match the corresponding resolution method. I personally think it is troublesome and unreliable, some machine experiments have found that some methods for obtaining the machine device type are not completely accurate, so it is best not to do this in terms of resolution and screen size. If it is really necessary to obtain the machine type, such as setting the default performance or something, do not get the machine type ready ~~