UIAdapter 1.3.1

UIAdapter 1.3.1

LEE维护。



UIAdapter 1.3.1

  • LEE

UIAdapter - iOS屏幕适配问题的优雅解决方案

License  Swift  Platform  Swift Package Manager  Carthage  Cocoapods

功能

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

安装

CocoaPods - Podfile

pod 'UIAdapter'

Carthage - Cartfile

github "lixiang1994/UIAdapter"

选择Xcode菜单 文件 > Swift Packages > 添加包依赖 并使用图形界面输入仓库URL。

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

Constraint UILabel Font

屏幕

例如。

// 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: "width 320")
    .width(._375, is: "width 375")
    .height(._844, is: "height 844")
    .height(._812, is: "height 812")
    .inch(._4_7, is: "4.7 inches")
    .inch(._5_8, is: "5.8 inches")
    .inch(._6_5, is: "6.5 inches")
    .level(.compact, is: "screen 3: 2")
    .level(.regular, is: "screen 16: 9")
    .level(.full, is: "screen 19.5: 9")
    .value
)

屏幕截图

TikTok 1

TikTok 2

贡献

如果您有需要实现的功能或遇到了bug,请提交一个问题。如果您已经扩展了UIAdapter的功能并希望其他人也能使用,请提交一个pull request。

授权

UIAdapter遵循MIT授权协议。有关更多信息,请参阅授权文件


欢迎加入交流群

QQ