In daily development, devices are often adapted to some extent. In order to facilitate unified management and use in multiple projects, SwiftyFitsize library is packaged and open source, which can be used to adapt views and font sizes, as well as support XIB and Storyboard

GitHub: SwiftyFitsize

The final result is shown below

The installation

Install using Cocoapods, or drag the project in manually

pod 'SwiftyFitsize'
Copy the code

use

The default SwiftyFitsize reference width is iphone6’s 375. If the device width selected for the design is different from the default, you can initialize the reference width in the AppDelegate file

SwiftyFitsize.reference(width: 414)
Copy the code

The resolution of some devices is listed below for easy search

equipment Logical resolution (Point) Device Resolution (Pixel)
SE 320×568 640×1136
6 times S over 7/8 375×667 750×1334
6 times S plus PI over 7 plus PI over 8 plus 414×736 1080×1920
X(S) 375×812 1125×2436
XR 414×896 828×1792
XS Max 414×896 1242×2688

It is also very convenient to use, just need to Number, UIFont, CGPoint, CGSize, UIEdgeInsetsMake and other types of values followed by ~

100~
UIFont.systemFont(ofSize: 14) ~CGPoint(x: 10, y: 10) ~CGSize(width: 100, height: 100) ~CGRect(x: 10, y: 10, width: 100, height: 100) ~UIEdgeInsetsMake(10.10.10.10) ~Copy the code
Xib/storyboard font adaptation

Support control UILabel UIButton UITextView UITextField

Xib/Storyboard constraint adaptation

Note: ~ please do not use nested with each other, such as

CGPoint(x: 10~, y: 10~) ~Copy the code