Skip to content

Latest commit

 

History

History
166 lines (119 loc) · 4.05 KB

README_CN.md

File metadata and controls

166 lines (119 loc) · 4.05 KB

AutoInch - 优雅的iPhone等比例/全尺寸精准适配工具

License  Swift  Platform  Swift Package Manager  Carthage  Cocoapods

特性

  • 数值类型快速转换
  • Storyboard 等比例适配支持
  • Xib 等比例适配支持
  • 自定义计算处理
  • 各个屏幕尺寸快速匹配

安装

CocoaPods - Podfile

pod 'AutoInch'

Carthage - Cartfile

github "lixiang1994/AutoInch"

使用

首先导入

import AutoInch

下面是一些简单示例. 支持所有设备和模拟器:

Auto

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())
    }
}

属性设置 (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:

约束 UILabel 字体大小

Inch

例子

// 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 inches screen numberOfLines = 2
label.numberOfLines = 0.screen.width(._320, is: 1).width(._375, is: 2).value
print("this is " +
    "default".screen
    .width(._320, is: "宽度 320")
    .width(._375, is: "宽度 375")
    .height(._844, is: "高度 844")
    .height(._812, is: "高度 812")
    .inch(._4_7, is: "4.7 英寸")
    .inch(._5_8, is: "5.8 英寸")
    .inch(._6_5, is: "6.5 英寸")
    .level(.compact, is: "屏幕级别 紧凑屏")
    .level(.regular, is: "屏幕级别 常规屏")
    .level(.full, is: "屏幕级别 全面屏")
    .value
)

截屏

TikTok 1

TikTok 2

贡献

如果您需要实现特定功能或遇到错误,请打开issue。 如果您自己扩展了AutoInch的功能并希望其他人也使用它,请提交拉取请求。

协议

AutoInch 使用 MIT 协议. 有关更多信息,请参阅LICENSE文件.


欢迎入群交流

QQ