BestFitImageView 通过比较其图像大小与其框架大小来自动选择最佳 contentMode。
如果图像的宽度和高度 小于 框架的宽度和高度,则将 contentMode 设置为 UIViewContentModeCenter。
否则,将 contentMode 设置为 UIViewContentModeScaleAspectFit。
您可以通过以下步骤手动包含 BestFitImageView
1) 将此仓库克隆到您的计算机本地,或按 下载 ZIP 仅下载最新的 master 提交。
2) 将 BestFitImageView.h 和 BestFitImageView.m 拖动到您的项目中,确保已选中 Copy items into destination group's folder (if needed)。
在您通常使用 UIImageView 的地方使用 BestFitImageView。根据图像的大小自动为您设置 contentMode。
除此之外,BestFitImageView 的行为与 UIImageView 相同。
BestFitImageView 仅 考虑其 image 的大小来确定 contentMode。
为了获得最佳结果,相关图像(例如 highlightedImage)应具有相同的大小。
BestFitImageView 在 MIT 许可证下提供(详见 LICENSE 文件以获取更多信息)。