- 数值类型快速转换
- Storyboard 等比例缩放适配支持
- Xib 等比例缩放适配支持
- 自定义缩放计算处理
- 各个屏幕尺寸快速匹配
CocoaPods - Podfile
pod 'UIAdapter'
Carthage - Cartfile
github "lixiang1994/UIAdapter"
选择 Xcode 菜单 File > Swift Packages > Add Package Dependency
输入仓库地址.
Repository: https://github.com/lixiang1994/UIAdapter
将以下内容添加到你的 Package.swift
:
.package(url: "https://github.com/lixiang1994/UIAdapter.git", from: "version")
首先导入
import UIAdapter
下面是一些简单示例. 支持所有设备和模拟器:
AutoLayout (SnapKit):
private func setupLayout() {
cardView.snp.makeConstraints { (make) in
make.top.equalTo(16.zoom())
make.left.right.equalToSuperview().inset(15.zoom())
make.bottom.equalTo(-26.zoom())
}
lineView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview().inset(15.zoom())
make.top.equalTo(titleLabel.snp.bottom)
make.height.equalTo(1)
}
titleLabel.snp.makeConstraints { (make) in
make.top.equalToSuperview()
make.left.equalTo(15.zoom())
make.height.equalTo(48.zoom())
}
stateLabel.snp.makeConstraints { (make) in
make.top.equalTo(lineView).offset(10.zoom())
make.left.equalTo(15.zoom())
make.height.equalTo(15.zoom())
}
}
属性设置 (Then):
private lazy var cardView = UIView().then {
$0.cornerRadius = 6.zoom()
$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.zoom(), weight: .medium)
}
private lazy var stateLabel = UILabel().then {
$0.textColor = .gray
$0.font = .systemFont(ofSize: 12.zoom(), weight: .medium)
}
Storyboard / Xib:
例子
// default other screen numberOfLines = 0
// 3.5 inches screen numberOfLines = 1
// 4.0 inches screen numberOfLines = 2
label.numberOfLines = 0.screen.inch(._3_5, is: 1).inch(._4_0, is: 2).value
// default other screen numberOfLines = 0
// width 320 screen numberOfLines = 1
// width 375 screen numberOfLines = 2
label.numberOfLines = 0.screen.width(equalTo: 320, is: 1).width(equalTo: 375, is: 2).value
print("this is " + "default".screen
.width(equalTo: 375, is: "宽度 等于 375")
.width(lessThan: 414, is: "宽度 小于 414")
.width(greaterThan: 414, is: "宽度 大于 414")
.height(equalTo: 700, is: "高度 等于 375")
.height(lessThan: 844, is: "高度 小于 844")
.height(greaterThan: 844, is: "高度 大于 844")
.inch(._4_7, is: "4.7 英寸")
.inch(._5_8, is: "5.8 英寸")
.inch(._6_5, is: "6.5 英寸")
.level(.compact, is: "屏幕级别 紧凑屏 (4:3)")
.level(.regular, is: "屏幕级别 常规屏 (16:9)")
.level(.full, is: "屏幕级别 全面屏 (19.5:9)")
.value
)
如果您需要实现特定功能或遇到错误,请打开issue。 如果您自己扩展了UIAdapter的功能并希望其他人也使用它,请提交拉取请求。
UIAdapter 使用 MIT 协议. 有关更多信息,请参阅LICENSE文件.