Sizes减少了评估所有可能设备大小、朝向和字体组合所需的时间。借助于Sizes,我们将避免启动所有受支持的设备模拟器、运行我们的应用程序并手动遍历每个屏幕,这不仅非常耗时,而且由于我们有时会忘记测试某些特定的组合,我们可能会意外地将带有布局错误的屏幕发布到App Store
⚠️ Sizes的弃用建议
Xcode 11引入了预览功能,这是一种类似于Sizes的快速验证UI的多场景的绝佳方法。如果您想了解更多关于Xcode预览的信息,我建议您观看这个WWDC会话。您甚至可以使用预览功能与UIKit一起使用,因此没有必要继续使用这个库。
将废弃此库,并将未来存档仓库。
📱 Sizes的实际应用
在10.5英寸iPad Pro上录制
Sizes最初是为了Brandon Williams和Stephen Celis在Playground中为Kickstarter iOS应用移植而创建的,并在PointFree中进一步解释了iOS。务必要查看他们的网站!
🌟 功能
- 在多个设备大小中检查您的应用程序
- 切换朝向
- 测试所有字体大小
- 通用(iPhone和iPad)
💡 演示
要运行示例项目,请克隆仓库并运行Sizes
目标。
📲 安装
CocoaPods
使用编辑您的Podfile
并指定依赖项
pod 'Sizes'
Carthage
使用编辑您的Cartfile
并指定依赖项
github "marcosgriselli/Sizes"
👩💻 如何使用
准备
尺寸需要使用自动布局(Auto Layout)来正确更新界面。
对于字体更新,您需要使用 动态字体(Dynamic Type)。
编程方式
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .headline, compatibleWith: traitCollection)
label.adjustsFontForContentSizeCategory = true
IB/Storyboard
设置
强烈建议您仅在 #DEBUG
模式下使用此功能。
设置尺寸的最佳方法是将 SizesWindow
用作 AppDelegates'
的窗口。这样将自动创建一个包含您的应用程序根视图控制器的 SizesViewController
实例,并且您可以没有任何问题地使用如 UIApplication.shared.windows.first?.rootViewController as? YourInitialCustomViewController
这样的代码。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if DEBUG
window = SizesWindow()
window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()!
window?.makeKeyAndVisible()
#endif
return true
}
用法
摇一摇以显示尺寸配置UI,然后点击其中一个方向/设备选项来触发变化。或者更新文本大小滑块以在不同的字体大小之间导航,您可以在滑动时获取字体名称。您可以在这条推文中查看更长的视频实现和一些Sizes的使用场景。
🛣 路线图
您可以通过GitHub 项目 或 问题 来了解新特性、修复或计划发布的概览。
❤️ 贡献
这是一个开源项目,因此请随意贡献。如何贡献?
查看 所有贡献者
📣 提及
👨💻 作者
Marcos Griselli | @marcosgriselli
🛡 许可证
MIT License
Copyright (c) 2018 Marcos Griselli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.