IOS gets screen resolution

Source: Internet
Author: User

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 ~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.