- Numerical type fast conversion
- Storyboard equal scale adaptation
- Xib equal scale adaptation
- Custom calculation processing
- Quick match for each screen size type
CocoaPods - Podfile
pod 'AutoInch'
Carthage - Cartfile
github "lixiang1994/AutoInch"
First make sure to import the framework:
import AutoInch
Here are some usage examples. All devices are also available as simulators:
AutoLayout (SnapKit):
private func setupLayout() {
cardView.snp.makeConstraints { (make) in
make.top.equalTo(16.auto())
make.left.right.equalToSuperview().inset(15.auto())
make.bottom.equalTo(-26.auto())
}
lineView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview().inset(15.auto())
make.top.equalTo(titleLabel.snp.bottom)
make.height.equalTo(1)
}
titleLabel.snp.makeConstraints { (make) in
make.top.equalToSuperview()
make.left.equalTo(15.auto())
make.height.equalTo(48.auto())
}
stateLabel.snp.makeConstraints { (make) in
make.top.equalTo(lineView).offset(10.auto())
make.left.equalTo(15.auto())
make.height.equalTo(15.auto())
}
}
Property (Then):
private lazy var cardView = UIView().then {
$0.cornerRadius = 6.auto()
$0.backgroundColor = .white
}
private lazy var lineView = UIView().then {
$0.backgroundColor = .hex("000000", alpha: 0.05)
}
private lazy var titleLabel = UILabel().then {
$0.textColor = .black
$0.font = .systemFont(ofSize: 20.auto(), weight: .medium)
}
private lazy var stateLabel = UILabel().then {
$0.textColor = .gray
$0.font = .systemFont(ofSize: 12.auto(), weight: .medium)
}
Storyboard / Xib:
e.g.
// default other screen numberOfLines = 0
// 3.5 inches screen numberOfLines = 1
// 4.0 inches screen numberOfLines = 2
label.numberOfLines = 0.screen.set(1, for: .inch(._3_5)).set(2, for: .inch(._4_0)).value
// default other screen numberOfLines = 0
// width 320 screen numberOfLines = 1
// width 375 inches screen numberOfLines = 2
label.numberOfLines = 0.screen.set(1, for: .width(._320)).set(2, for: .width(._375)).value
print("this is " +
"default".screen
.set("width 320", for: .width(._320))
.set("width 375", for: .width(._375))
.set("height 844", for: .height(._844))
.set("height 812", for: .height(._812))
.set("4.7 inches", for: .inch(._4_7))
.set("5.8 inches", for: .inch(._5_8))
.set("6.5 inches", for: .inch(._6_5))
.set("screen 3: 2", for: .level(.compact))
.set("screen 16: 9", for: .level(.regular))
.set("screen 19.5: 9", for: .level(.full))
.value
)
If you have the need for a specific feature that you want implemented or if you experienced a bug, please open an issue. If you extended the functionality of AutoInch yourself and want others to use it too, please submit a pull request.
AutoInch is under MIT license. See the LICENSE file for more info.