要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
。
您可以通过将 UIImageViewAlignedSwift 添加为包依赖项来将其添加到 Xcode 项目中。
https://github.com/sochalewski/UIImageViewAlignedSwift
。CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 UIImageViewAlignedSwift 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
pod 'UIImageViewAlignedSwift'
然后,运行以下命令
$ pod install
Carthage 是一个去中心化的依赖管理器,它构建您的依赖项并为您提供二进制框架。
您可以使用 Homebrew 使用以下命令安装 Carthage
$ brew update
$ brew install carthage
要使用 Carthage 将 UIImageViewAlignedSwift 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "sochalewski/UIImageViewAlignedSwift"
运行 carthage update
来构建框架,并将构建的 UIImageViewAlignedSwift.framework
拖入您的 Xcode 项目中。
它是 UIImageView
的一个子类,允许您自定义显示在视图框架内的图像的对齐方式。即使 contentMode
设置为 .scaleAspectFit
、.scaleAspectFill
或 .scaleToFill
,这也有效。
它是基于原始的 reydanro 的 UIImageViewAligned 重写为 Swift 的版本。
因为有很多很棒的类别是基于 UIImageView
构建的。子类化标准的 UIView
将意味着失去它们。
例如,AFNetworking
的异步 UIImageView
类别在使用这个容器类时可以完美地工作,您无需担心任何事情。
初始化时,UIImageViewAligned
将创建一个内部的 UIImageView
,它将实际保存显示的图像。主类然后只是重新定位这个内部的 UIImageView
以实现您期望的对齐方式。
在运行时,您可以更改 image
、contentMode
或 alignment
,图像将正确地重新定位自身。
UIImageViewAligned
的 image
属性被覆盖以将调用转发到内部的 UIImageView
,因此您可以直接拖放到您的应用程序中。
Piotr Sochalewski,sochalewski.github.io
UIImageViewAlignedSwift 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。