[![CI Status](http://img.shields.io/travis/Chen Shenghan/ZZScale.svg?style=flat)](https://travis-ci.org/Chen Shenghan/ZZScale)
Have you face the problem that you only got 1 set of design from your designer, but you have to adapt multiple screens?
Yes, you can do everything by auto-layout or manually code layout, but you have to define a lot of strategies for all places that need to be care when adapt for differnt screen size.
Is there a much simpler way to do that? Yes, I provide a solution: ZZScale.
This is how it works:
- Scale your container view by ratio, either by width or height, when
viewDidLoad
- You treat the layout just like in your designed screen size, if the runtime screen size is the same ratio as your designed screen size.
- When runtime screen size is not the same ratio as your designed screen size, it scales by the priority side (width or height), and leave the other side for further layout method.
- And yes, it works with auto-layout!
Here is an example:
You have a scrollable screen that you want all users to see it in just same horizontal layout of iPhone6 in every devices, you can just insert the code self.view.zz_scaleInFactorRelativeByWidth(375)
in viewDidLoad
of your UIViewController
.
Here is another example:
You have a non-scrollable screen that you want all users to see it in just same vertical layout of iPhone6 in every devices, you can just insert the code self.view.zz_scaleInFactorRelativeByHeight(667)
in viewDidLoad
of your UIViewController
.
To run the example project, clone the repo, and run pod install
from the Example directory first.
ZZScale is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ZZScale"
Chen Shenghan, zzdjk6@gmail.com
ZZScale is available under the MIT license. See the LICENSE file for more info.