Ios determines whether the screen is displayed as @ 2x or @ 3x to call the font size, @ 2x @ 3x

Source: Internet
Author: User

Ios determines whether the screen is displayed as @ 2x or @ 3x to call the font size, @ 2x @ 3x

Traditional font size adaptation may be based on a ratio of the screen width to the iPhone 5 or iPhone 6 width. However, if you have such a requirement, a font is displayed on the mobile phone that displays the @ 2x image, and another fixed-size font is displayed on the mobile phone that displays the @ 3x image.

Therefore, the focus here is to distinguish between the mobile phone screen display image type @ 2x or @ 3x.

CGFloat scale = [UIScreen mainScreen]. scale. The scale attribute of UIScreen is 2 for iphone 5, 6 s, 7, 8, and 3 for iPhone plus and iphone X. So we have the following macro definition.

/* Font related */

# Define kScreenScale [UIScreen mainScreen]. scale // The iphone 3gs is 1; 4, 5, 5S, 6, 7, 8, etc. 2; plus X is 3

// @ 3x the screen size is 1.5 times that of @ 2x.

# Define kFontAuto (size) [UIFont systemFontOfSize :( size * kScreenScale/2.0)]

 

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.